Installing Python and distribute on Windows 7 gives "Writing failed ... permission denied"

Jonathan Hartley picture Jonathan Hartley · Jan 21, 2012 · Viewed 8.8k times · Source

I'm on Windows 7 (which I fully admit I don't understand the permissions model of. I'm reading about it in other tabs.) My user is an administrator. When I try to run "python distribute_setup.py" I get "writing failed ... permission denied" errors and then "error: can't create or remove files in install directory".

I've freshly installed the Python 3.2.2 MSI installer from python.org.

I'm installing 32-bit Python even though I'm on 64 bit Windows, because I will have some dependencies that require it (pyglet, an OpenGL library.)

I download distribute_setup.py and run "python distribute_setup.py" from the command-line.

Halfway through the massive amounts of useless text this spews are some hidden error messages:

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'

These three lines are repeated about twenty times, then:

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'

The directory "E:\Program Files (x86)\Python3.2.2\Lib" allows "full control" by administrators. My user is an administrator (and the checked permissions checkboxes are all greyed out - I couldn't turn off "full control" nor any other permissions even if I wanted to.)

I speculatively tried adding "full control" to the "Users" group as well as the "administrators" group. Rerunning, I no longer get the same errors, but it exits at the same point, with:

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

There is no "E:\Program Files (x86)\Python3.2.2\Scripts" directory. I create one. It is owned by "administrators", and has "full control" set for administrators. I notice that all other Python files and directories are owned by "SYSTEM". Running again gives:

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

Even though the 'Scripts' dir has 'full control' granted for administrators, I try speculatively adding 'full control' for Users group. Rerunning does produce some warnings:

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'

but appears to complete successfully.

However, then running "easy_install virtualenv" produces a User Account Control dialog "Do you want to allow the following program from an unknown publisher to make changes to this computer?" and then creates a new CMD window, which flashes by and disappears too fast to see, and did not appear to work: virtualenv has not been installed.

I'd like to stop the UAC dialog from appearing every time. It's annoying: "easy_install" is a program I trust, and I shouldn't need to confirm every time I run it. All of the solutions I can find to stop the UAC dialog from appearing involve creating a magic double-clickable shortcut to the executable. I haven't found anything for command-line applications.

I'd also like to stop easy_install from launching in a new cmd window. This makes it impossible to see the output. This problem appears to be independent from the UAC dialog, because turning off UAC globally means easy_install will run without the dialog, but it still runs in a new window.

What's going on here? What am I doing wrong?

Answer

jgritty picture jgritty · Jan 21, 2012

It seems that you have to use the "Run as administrator" option when opening the command prompt, because, as your wife says, "Windows is f****d". As you seem to also have discovered, turning off UAC is one way to avoid getting a UAC dialog when doing so.