Using Microsoft Visual C with Python¶
Visual studio compiler versions¶
Here is a list of Visual Studio / Visual C++ version numbers, the value of
_MSC_VER during compilation, the alternative year-based name,
and the C / C++ runtime library.
For sources on version numbers /
For VC runtime libraries:
|VC++ version||_MSC_VER||Alternative name||C runtime||C++ runtime|
|5.0||1100||Visual Studio 97||MSVCRT.DLL||MSVCP50.DLL|
|7.0||1300||Visual Studio 2002||MSVCR70.DLL||MSVCP70.DLL|
|7.1||1310||Visual Studio 2003||MSVCR71.DLL||MSVCP71.DLL|
|8.0||1400||Visual Studio 2005||MSVCR80.DLL||MSVCP80.DLL|
|9.0||1500||Visual Studio 2008||MSVCR90.DLL||MSVCP90.DLL|
|10.0||1600||Visual Studio 2010||MSVCR100.DLL||MSVCP100.DLL|
|11.0||1700||Visual Studio 2012||MSVCR110.DLL||MSVCP110.DLL|
|12.0||1800||Visual Studio 2013||MSVCR120.DLL||MSVCP120.DLL|
|14.0||1900||Visual Studio 2015||See notes||MSVCP140.DLL|
For 2015, MS split the C runtime into two component libraries. See:
- blog post on the the universal CRT
- Steve Dower’s first blog post: Python 3.5 extensions part 1;
- Steve’s second blog post: Python 3.5 extensions part 2;
The CRT components are:
ucrtbase.dl: “The Universal CRT (UCRT) contains the functions and globals exported by the standard C99 CRT library. The UCRT is now a Windows component, and ships as part of Windows 10.” (see CRT 2015).
vcruntime140.dll: “The vcruntime library contains Visual C++ CRT implementation-specific code, such as exception handling and debugging support, runtime checks and type information, implementation details and certain extended library functions. This library is specific to the version of the compiler used.” (CRT 2015);
The C++ runtime for VS2015 is
MSVCP140.dll (CRT 2015).
Visual Studio versions used to compile distributed Python binaries¶
The version of Visual Studio is described in
readme.txt in the
folder of the source distribution. The full Visual C++ version number is in
release.props. I read these files from the
CPython Hg web interface for each tagged
|Python version||VC++ version|
Installing free versions of Microsoft Visual C / C++¶
Pythons 2.7 (and 3.2)¶
If you are compiling for Python 2.7, you should first try the installer at
http://aka.ms/vcpython27. I installed this for all users from a
Window opened with “run as administrator”, like this:
msiexec /i VCForPython27.msi ALLUSERS=1
This command line comes from the “Install instructions” on the download page. For me, the installer runs but closes without showing any signs that it has finished. The compilers seem to work fine nevertheless. If this standalone Python 2.7 compiler set works for you, you should be able to compile both 32 and 64 bit extensions without further configuration. If not, see Other options for MSVC installation.
Pythons 3.3 and 3.4¶
For Pythons 3.3 and 3.4 you will need MSVC 2010.
Compiling for 64-bit¶
For 64-bit compiles, I recommend you get your compilers via the Window 7.1 SDK.
This includes the VS 10 / 2010 command line compilers you need to compile
Python extensions. I found that I needed to install from the offline ISO
you will see in the “Install Instructions”, choose
I believe Windows 8, 10 and server 2012 can mount ISO files from explorer. For Windows 7 / server 2008 I used Virtual clone drive to mount the ISO files.
To run the install, navigate to the folder
Setup on the DVD image, and run
SDKSetup.exe. Otherwise you may get an error about .NET components that
cannot be installed.
Finally, for 64-bits, I needed to apply this patch to avoid a distutils
compilation error ending in
echo "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 > "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64/vcvars64.bat"
Python 3.5, 3.6¶
For Python 3.5 and 3.6 32-bit and 64-bit extensions you need MSVC 14 / 2015. Your fastest route to success will likely be the MSVC 2015 command line tools. Install these first. To get Python to recognize the MSVC command line tools, you will need a version of the setuptools package >= 24.0. Check by:
python -c 'import setuptools; print(setuptools.__version__)'
If your version is < 24.0, then:
pip install --upgrade setuptools
See the Python Windows compilers wiki page for more details.
Another option is to install the whole VS 2015 community edition. It’s a huge 11GB install which took more than an hour on my machine. Do a custom install, and select the VC++ compiler component (it is not selected by default).
Other options for MSVC installation¶
If the VS for Python 2.7 installer doesn’t work for you, or you can’t get VS 2010 compilation working for 3.3 / 3.4, see the links below.
In overview, you may be able to find the free Visual Studio express download that you need on the Microsoft site, but until VS 2015, these do not compile 64-bit extensions by default. The instructions above give the easiest way to get 64-bit compiles working, but you can also try the other methods given in the links below.