I downloaded Microsoft Visual C++ Compiler for Python 2.7 , and install it, the full path of vcvarsall.bat
is:
C:\Users\UserName\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat
But the following code can't return the path of it:
from distutils import msvc9compiler msvc9compiler.find_vcvarsall(9.0)
The installer doesn't write the install information to the registry, and from the source code of find_vcvarsall()
, it seems that it can't find the vcvarsall.bat
file from VS90COMNTOOLS
setting, because it requires that the name of the folder that contains vcvarsall.bat
is VC
:
productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC")
How can I use the compiler without modify registry or folder name?
Visual Studio is a powerful Python IDE on Windows. Visual Studio provides open-source support for the Python language through the Python Development and Data Science workloads (Visual Studio 2017 and later) and the free Python Tools for Visual Studio extension (Visual Studio 2015 and earlier).
The use of Microsoft Visual C++ Compiler for Python 2.7 is recommended (If you don't need to compile for ia64).
The Visual Studio build tools include a C compiler that you can use to create everything from basic console programs to full Windows Desktop applications, mobile apps, and more.
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 using pip
.
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.
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=1 SET 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With