Microsoft Visual C++ Compiler for Python 2.7
Update setuptools to 6.0 or greater. In those version setuptools can autodetect Microsoft Visual C++ Compiler for Python 2.7 with the vcvarsall.bat.
Please reference to:
Look in the setup.py
file of the package you are trying to install. If it is an older package it may be importing distutils.core.setup()
rather than setuptools.setup()
.
I ran in to this (in 2015) with a combination of these factors:
The Microsoft Visual C++ Compiler for Python 2.7 from http://aka.ms/vcpython27
An older package that uses
distutils.core.setup()
Trying to do
python setup.py build
rather than usingpip
.
If you use a recent version of pip, it will force (monkeypatch) the package to use setuptools, even if its setup.py
calls for distutils. However, if you are not using pip, and instead are just doing python setup.py build
, the build process will use distutils.core.setup()
, which does not know about the compiler install location.
Solution
Step 1: Open the appropriate Visual C++ 2008 Command Prompt
Open the Start menu or Start screen, and search for "Visual C++ 2008 32-bit Command Prompt" (if your python is 32-bit) or "Visual C++ 2008 64-bit Command Prompt" (if your python is 64-bit). Run it. The command prompt should say Visual C++ 2008 ... in the title bar.
Step 2: Set environment variables
Set these environment variables in the command prompt you just opened.
SET DISTUTILS_USE_SDK=1SET MSSdk=1
Reference http://bugs.python.org/issue23246
Step 3: Build and install
cd
to the package you want to build, and run python setup.py build
, then python setup.py install
. If you want to install in to a virtualenv, activate it before you build.
Christian Long provides a practicable solution. But if you do not want to modify it in "Visual C++ 2008 32-bit/64-bit Command" every time, you can simply find out the location of "vcvarsall.bat", i.e. "C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat", and then modify find_vcvarsall(version) function in Python27\Lib\distutils\msvc9compiler.py
like this:
def find_vcvarsall(version): productdir= "C:/Users/UserName/AppData/Local/Programs/Common/Microsoft/Visual C++ for Python/9.0" vcvarsall = os.path.join(productdir, "vcvarsall.bat") if os.path.isfile(vcvarsall): return vcvarsall else: return None
Simple, ugly but useful.
Note that Microsoft no longer lets you download the required Visual Studio 2008 VC++ Build Tools, but the file can be found in the archive: https://web.archive.org/web/20210106040224/https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi