Value error trying to install Python for Windows extensions

Question:

I have Microsoft Visual Studio 2008 installed already. I downloaded the zip file Python for Windows extensions and extracted the contents into my Python27 folder. There’s now a subfolder called pywin32-214. (Is the 32 part a problem? I’m on a 64-bit system.) Here’s a transcript from the command line:

C:Python27pywin32-214>setup.py -q install
Building pywin32 2.7.214.0
Traceback (most recent call last):
  File "C:Python27pywin32-214setup.py", line 2152, in <module>
    ('', ('pywin32.pth',)),
  File "C:Python27libdistutilscore.py", line 152, in setup
    dist.run_commands()
  File "C:Python27libdistutilsdist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:Python27libdistutilsdist.py", line 972, in run_command
    cmd_obj.run()
  File "C:Python27pywin32-214setup.py", line 1251, in run
    install.run(self)
  File "C:Python27libdistutilscommandinstall.py", line 563, in run
    self.run_command('build')
  File "C:Python27libdistutilscmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:Python27libdistutilsdist.py", line 972, in run_command
    cmd_obj.run()
  File "C:Python27pywin32-214setup.py", line 596, in run
    build.run(self)
  File "C:Python27libdistutilscommandbuild.py", line 127, in run
    self.run_command(cmd_name)
  File "C:Python27libdistutilscmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:Python27libdistutilsdist.py", line 972, in run_command
    cmd_obj.run()
  File "C:Python27libdistutilscommandbuild_ext.py", line 340, in run
    self.build_extensions()
  File "C:Python27pywin32-214setup.py", line 858, in build_extensions
    self.compiler.initialize()
  File "C:Python27libdistutilsmsvc9compiler.py", line 383, in initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:Python27libdistutilsmsvc9compiler.py", line 299, in query_vcvarsal
l
    raise ValueError(str(list(result.keys())))
ValueError: [u'path']

I don’t know what to make of this. Help?

Asked By: user460847

||

Answers:

Python for Windows extensions is only supported on

32-bit MS Windows (95/98), 32-bit MS
Windows (NT/2000/XP), All 32-bit MS
Windows (95/98/NT/2000/XP), Win2K,
WinXP, WinCE

Taken from the sourceforge project page. Seems like you may be out of luck!

EDIT: However… reading this seems to imply otherwise.

Answered By: William

If you have a 64 bit Python installation:

Install “Microsoft Visual Studio 2008 Professional Edition” with the “X64 Compiler and Tools” option enabled.

Alternatively, download pywin32-214.win-amd64-py2.7.exe from http://sourceforge.net/projects/pywin32/files/pywin32/Build%20214/

Answered By: cgohlke

Another possible reason for this problem to appear is that you have just installed Visual Studio and the command prompt you’re using had been hanging around from the time before the installation.

This is because MSVC installer sets few environment variables and one of these variables ( VS90COMNTOOLS )has to be set for vcvarsall.bat to execute correctly.
But each running program in Windows holds its own local copy of environment variables that gets inherited (copied) from parent process upon child start-up. Thus, after child has started, it does not receive alterations performed on the system-level envvars. And the only way of getting updated environment variables is trough spawning a new instance of a child process with parent that has updated version of envvars.

Answered By: Ilya

As stated it’s trying to use a 32-bit compiler for 64-bit python. I was able to build successfully by:

  1. Finding vcvarsx86_amd64.bat in C:Program Files (x86)Microsoft Visual Studio 12.0VCbinx86_amd64 (depends on your setup)
  2. Open a cmd prompt
  3. Run SET VS90COMNTOOLS=%VS120COMNTOOLS% (depends on setup, see https://stackoverflow.com/a/10558328/2362877)
  4. Run vcvarsx86_amd64.bat
  5. Then pip install <package>
Answered By: frmdstryr

I tried all the other answers and a lot more.
Ended up installing python 32-bit, which fixed the issue right away.

If this is an option, it’s most likely the easiest fix.

Answered By: Sanjii

If you are fixed on Python 2.7 64-bit (like I am) and too cheap to buy VS2008 Professional, you can also download VS2008 Express and install the Windows 7 SDK to get a compatible 64-bit compiler for free. After that, run the Windows 7 SDK SetEnv.Cmd script and then the setup.py:

> "C:Program FilesMicrosoft SDKsWindowsv7.1BinSetEnv.Cmd"
> setup.py -q install

The SetEnv.Cmd should set up all the environment variables you need for build. When it runs, there should be a message that says “Targeting Windows 7 x64 Debug”. You can also use this command to compile in Release mode:

> "C:Program FilesMicrosoft SDKsWindowsv7.1BinSetEnv.Cmd" /Release
> setup.py -q install
Answered By: mmitchell

None of these answers worked for me but I found the solution on the issue tracker:

  1. Open cmd.
  2. cd “C:Program Files (x86)Microsoft Visual Studio 9.0VCbin”
  3. Type vcvars32.bat or vcvars64.bat
  4. In the same prompt and -without closing: cd back to the Python module you’re trying to install.
  5. The code should now install.

Source: http://bugs.python.org/issue7511

Answered By: Matthew Roberts
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.