在Windows 7安装Python和distribute出现“写入失败... 权限被拒绝”

2 投票
2 回答
8913 浏览
提问于 2025-04-17 10:45

我在使用Windows 7(我承认我对它的权限设置不太了解,正在其他页面上查资料)。我的用户是管理员。当我尝试运行“python distribute_setup.py”时,出现了“写入失败...权限被拒绝”的错误,接着又出现“错误:无法在安装目录中创建或删除文件”的提示。

我刚从python.org上安装了Python 3.2.2的MSI安装包。

虽然我的系统是64位的,但我还是安装了32位的Python,因为我有一些依赖项需要它(比如pyglet,这是一个OpenGL库)。

我下载了distribute_setup.py,并在命令行中运行“python distribute_setup.py”。

在这段输出的冗长信息中,隐藏着一些错误信息:

root: Generating grammar tables from E:\Program Files (x86)\Python3.2.2\Lib\lib2to3\PatternGrammar.txt
root: Writing grammar tables to E:\Program Files (x86)\Python3.2.2\Lib\lib2to3\PatternGrammar3.2.2.final.0.pickle
root: Writing failed:[Errno 13] Permission denied: 'E:\\Program Files (x86)\\Python3.2.2\\Lib\\lib2to3\\PatternGrammar3.2.2.final.0.pickle'

这三行信息重复了大约二十次,然后:

Scanning installed packages
No setuptools distribution found
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: 'E:\\Program Files (x86)\\Python3.2.2\\Lib\\site-packages\\test-easy-install-5924.write-test'

目录“E:\Program Files (x86)\Python3.2.2\Lib”允许管理员“完全控制”。我的用户是管理员(而且权限的复选框都是灰色的——即使我想,也无法关闭“完全控制”或其他权限)。

我尝试给“用户”组和“管理员”组都添加“完全控制”的权限。重新运行后,我不再收到相同的错误,但在同一位置退出,显示:

Scanning installed packages
No setuptools distribution found
build\src\setuptools\command\easy_install.py:289: UserWarning: Unbuilt egg for distribute [unknown version] (c:\users\jhartley\appdata\local\temp\tmpr0dzkz\distribute-0.6.24\build\src)
  self.local_index = Environment(self.shadow_path+sys.path)
warning: no files found matching 'Makefile' under directory 'docs'
warning: no files found matching 'indexsidebar.html' under directory 'docs'
error: E:\Program Files (x86)\Python3.2.2\Scripts: Access is denied

没有“E:\Program Files (x86)\Python3.2.2\Scripts”这个目录。我自己创建了一个。它的所有者是“管理员”,并且为管理员设置了“完全控制”的权限。我注意到其他所有Python文件和目录的所有者都是“SYSTEM”。再次运行后显示:

Scanning installed packages
No setuptools distribution found
build\src\setuptools\command\easy_install.py:289: UserWarning: Unbuilt egg for distribute [unknown version] (c:\users\jhartley\appdata\local\temp\tmp1kmbk6\distribute-0.6.24\build\src)
  self.local_index = Environment(self.shadow_path+sys.path)
warning: no files found matching 'Makefile' under directory 'docs'
warning: no files found matching 'indexsidebar.html' under directory 'docs'
error: E:\Program Files (x86)\Python3.2.2\Scripts\easy_install-script.py: Permission denied

尽管“Scripts”目录已经为管理员授予了“完全控制”的权限,我还是尝试给“用户”组添加“完全控制”的权限。重新运行后出现了一些警告:

Scanning installed packages
No setuptools distribution found
build\src\setuptools\command\easy_install.py:289: UserWarning: Unbuilt egg for distribute [unknown version] (c:\users\jhartley\appdata\local\temp\tmp31bznf\distribute-0.6.24\build\src)
  self.local_index = Environment(self.shadow_path+sys.path)
warning: no files found matching 'Makefile' under directory 'docs'
warning: no files found matching 'indexsidebar.html' under directory 'docs'

但似乎成功完成了。

然而,当我运行“easy_install virtualenv”时,出现了用户帐户控制对话框“您是否允许以下来自未知发布者的程序对这台计算机进行更改?”然后打开了一个新的CMD窗口,闪过一下就消失了,根本没看到内容,virtualenv并没有安装成功。

我希望能停止每次都弹出UAC对话框。这太烦人了:“easy_install”是我信任的程序,我不应该每次运行都需要确认。我找到的所有停止UAC对话框的方法都涉及创建一个神奇的双击快捷方式来运行可执行文件,但我没有找到适用于命令行应用程序的解决方案。

我还希望停止easy_install在新的cmd窗口中启动。这让我无法看到输出。这个问题似乎和UAC对话框无关,因为全局关闭UAC后,easy_install可以在没有对话框的情况下运行,但仍然是在新窗口中运行。

这到底是怎么回事?我哪里做错了?

2 个回答

1

明确地给我自己的用户在整个系统的Python安装目录及其子目录中“完全控制”的权限,这样就能让easy_install正常工作了。

不过,这样做还不是完全令人满意:

  • easy_install还是会弹出用户账户控制(UAC)的对话框。我希望能关闭这个对话框,因为我信任easy_install这个程序。
  • easy_install还是会在一个新的命令窗口中启动,然后这个窗口又会消失,所以如果我需要查看输出(比如之前出错的时候),就看不到了。
5

看起来你在打开命令提示符的时候需要选择“以管理员身份运行”,因为就像你老婆说的,“Windows真是麻烦”。而且你似乎也发现了,关闭用户帐户控制(UAC)是避免弹出UAC对话框的一种方法。

撰写回答