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
martineau
  • 119,623
  • 25
  • 170
  • 301
Mike M. Lin
  • 9,992
  • 12
  • 53
  • 62
  • 1
    Also note that switching to the mingw32 compiler [doesn't work for all extensions](https://mail.python.org/pipermail/python-list/2010-April/573869.html). – martineau Nov 22 '13 at 00:37
  • @martineau Microsoft has released a compiler package for Python 2.7 – for more information see my comment to my answer. – Piotr Dobrogost Oct 18 '14 at 10:57

2 Answers2

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

Community
  • 1
  • 1
Piotr Dobrogost
  • 41,292
  • 40
  • 236
  • 366
  • 57
    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. – tponthieux Jun 08 '12 at 21:54
  • 2
    @tponthieux That's why [installation](http://stackoverflow.com/a/5442340/95735) from binary packages on Windows is so handy. – Piotr Dobrogost Apr 01 '13 at 19:01
  • 2
    @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. – Brendan Abel May 07 '13 at 05:37
  • 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) – Mark Harviston Jul 01 '13 at 03:12
  • You can install the 64 bit compiler with the W7 SDK and then copy a bat to the "expected location". http://stackoverflow.com/a/19915585/905908 – PAT Nov 11 '13 at 20:49
  • 7
    Since MSVC++ 2008 Express is not longer available, they should update the Windows build to [MSVC++ 2010 Express](http://www.visualstudio.com/en-us/downloads) which can still be obtained -- although doing so would have a ripple effect... – martineau Nov 22 '13 at 00:21
  • 1
    MSVC++ 2008 Express is not available from Microsoft, but it seems you can download an "unofficial" but legal copy from softonic at http://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) – Víctor Velarde Feb 04 '14 at 17:02
  • 1
    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) – stmax Feb 19 '14 at 22:29
  • 6
    @tponthieux "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: http://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 https://mail.python.org/pipermail/distutils-sig/2014-September/024885.html for announcement. – Piotr Dobrogost Sep 28 '14 at 09:58
  • 1
    @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? – ARF Mar 09 '15 at 23:06
  • @martineau 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? – lordscales91 Mar 02 '16 at 16:38
  • @lordscales91: I'm not sure. Maybe you could use the link in [this answer](http://stackoverflow.com/a/3061839/355230) to download it from `download.microsoft.com`. – martineau Mar 02 '16 at 16:58
  • what is your python version? I updated to 2.7.12, and problem solved.... – John Smith Jun 29 '16 at 07:07
  • I see nothing in [release notes](https://www.python.org/downloads/release/python-2712/) 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](https://github.com/pypa/setuptools/blob/master/CHANGES.rst) of setuptools neither. – Piotr Dobrogost Jun 29 '16 at 08:42
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.

楊宇恩
  • 99
  • 2
  • 11