How do I point easy_install to vcvarsall.bat?
Asked Answered
R

2

46

I already have MSVC++ 2010 Express installed, and my vcvarsall.bat file is at C:\Program Files\Microsoft Visual Studio 10.0\VC, which is in my system PATH. When I run easy_install, it can't find vcvarsall.bat.

Is there something I need to set in my distutils.cfg file to point it to my MSVC++ installation?

G:\>easy_install hg-git
install_dir C:\Python26\Lib\site-packages\
Searching for hg-git
Best match: hg-git 0.2.6
Processing hg_git-0.2.6-py2.6.egg
hg-git 0.2.6 is already the active version in easy-install.pth

Using c:\python26\lib\site-packages\hg_git-0.2.6-py2.6.egg
Processing dependencies for hg-git
Searching for dulwich>=0.6.0
Reading http://pypi.python.org/simple/dulwich/
Reading http://samba.org/~jelmer/dulwich
Reading http://launchpad.net/dulwich
Best match: dulwich 0.7.1
Downloading http://www.samba.org/~jelmer/dulwich/dulwich-0.7.1.tar.gz
Processing dulwich-0.7.1.tar.gz
Running dulwich-0.7.1\setup.py -q bdist_egg --dist-dir c:\docume~1\mlin\locals~1
\temp\easy_install-fhraep\dulwich-0.7.1\egg-dist-tmp-qozily
error: Setup script exited with error: Unable to find vcvarsall.bat
Rodmun answered 1/7, 2011 at 18:17 Comment(2)
Also note that switching to the mingw32 compiler doesn't work for all extensions.Waggish
@Waggish Microsoft has released a compiler package for Python 2.7 – for more information see my comment to my answer.Bluefish
B
57

I'd still like to know where to set that reference to vsvarsall.bat...

Well, as martineau wrote you have to have either Visual Studio 2008 or Visual C++ Express installed. Having said that I understand you would like to know where Python looks for this batch file. You can see this by looking at definition of find_vcvarsall function in distutils/msvc9compiler.py standard module. Python checks in turn if any of folders saved in the registry under keys

  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VCExpress\9.0\Setup\VC\ProductDir

(for 64bit Windows) or

  • HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir
  • HKEY_LOCAL_MACHINE\Software\Microsoft\VCExpress\9.0\Setup\VC\ProductDir

(for 32bit Windows) exists and if so it treats such folder as the one containing vcvarsall.bat file. If none of these folders exists Python checks if there's environment variable VS90COMNTOOLS. If this variable exits Python treats folder two levels above value of this variable as the folder containing vcvarsall.bat file.

See also my other answer which explains why you can't use MSVC++ 2010 to build extensions for Python 2.6

EDIT: The VC++ 2008 files are now packaged in an installer from MS which can be downloaded here. Once installed vcvarsall.bat will be in C:\Users\username\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

Bluefish answered 2/1, 2012 at 21:54 Comment(14)
Too bad Python doesn't come bundled with gcc. Downloading a 3.3GB VS 2008 iso just to be able to use setuptools on 64 bit Windows with 64 bit Python is kind of absurd.Spiteful
@Spiteful That's why installation from binary packages on Windows is so handy.Bluefish
@PiotrDobrogost True. But many of the packages up on pypi don't have precompiled binary installers, and so installing from source is the only option.Coprolite
you can use the mingw compiler with many python modules, just set [build] compiler=mingw in your distutils.cfg (though this often won't work since msvc is the "official" windows compiler for cpython)Pelisse
You can install the 64 bit compiler with the W7 SDK and then copy a bat to the "expected location". https://mcmap.net/q/13228/-errors-while-building-installing-c-module-for-python-2-7Mcdaniel
Since MSVC++ 2008 Express is not longer available, they should update the Windows build to MSVC++ 2010 Express which can still be obtained -- although doing so would have a ripple effect...Waggish
MSVC++ 2008 Express is not available from Microsoft, but it seems you can download an "unofficial" but legal copy from softonic at microsoft-visual-cpp-2008-express.softonic.com. You can then add 'c:/Program files/Microsoft Visual Studio 0.0/VC' to your PATH (PIP on a VIRTUALENV could find the C++ compiler for a Python2.7 with that configuration)Bullheaded
MSVC++ 2008 Express is still available for MSDN subscribers. Here are some SHA1 checksums if you want to verify the validity of ISOs downloaded from somewhere else: en_visual_studio_2008_express_x86_dvd_x13-97868.iso (76c6d28274a67741da720744026ea991a70867d1), en_visual_studio_2008_express_with_service_pack_1_x86_dvd_x15-04728.iso (937bd4a1b299505f286e371b3a5212b9098c38f2)Daven
@Spiteful "Microsoft has released a compiler package for Python 2.7 to make it easier for people to build and distribute their C extension modules on Windows. The Microsoft Visual C++ Compiler for Python 2.7 (a.k.a. VC9) is available from: aka.ms/vcpython27" "It's free (VC Express 2008 is behind a pay wall these days) It's small (85MB download, 300mb on installed) It's a per-user install with no reboot required" - Steve Dower. See mail.python.org/pipermail/distutils-sig/2014-September/… for announcement.Bluefish
@PiotrDobrogost Since the Microsoft compiler package is installed on a per-user basis, distutils does not find it. (At least on my machine.) Do I need to manually set the registry keys? Even when setting these keys, it complains about missing header files, e.g. stdint.h, when I try to compile an extension. Any idea what is going on?Whit
@Waggish Reporting news here, 2010 is not available anymore (officially) at the time of writing. You can find the installer googling a bit but I'm wondering whether those are safe or not. Otherwise are we forced to purchase VS2010 to compile Python 3.x extensions on Windows?Colson
@lordscales91: I'm not sure. Maybe you could use the link in this answer to download it from download.microsoft.com.Waggish
what is your python version? I updated to 2.7.12, and problem solved....Hutchinson
I see nothing in release notes of Python 2.7.12 which would suggest something was changed in this regard. find_vcvarsall function is patched by setuptools but I don't see anything relevant in changelog of setuptools neither.Bluefish
Q
0

Met same problem on python 3.9.12 (anaconda),I install Visual C++ for Python at C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

and find the msvc9compiler.py at

C:\Users\UserName\anaconda3\Lib\distutils showed
VS_BASE = r"Software\Microsoft\VisualStudio%0.1f"

how to point the vcvarsall.bat to python ?

(I added the system PATH but not working at all.) C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0

May you please point out how to add registry for the value? I did't find HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir in my PC.

Quintessa answered 17/11, 2022 at 5:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.