Using Microsoft Visual C with Python¶
Visual studio compiler versions¶
Here is a list of Visual Studio /Visual C++ version numbers, the value ofthe defined_MSC_VER
during compilation, the alternative year-based name,and the C / C++ runtime library.
For sources on version numbers /_MSC_VER
:
For VC runtime libraries:
the MSC runtime library pages;
VC++ version | _MSC_VER | Alternative name | C runtime | C++ runtime |
---|---|---|---|---|
1.0 | 800 | MSVCRT10.DLL | ||
2.0 | 900 | MSVCRT20.DLL | ||
4.0 | 1000 | MSVCRT40.DLL | ||
4.2 | 1020 | MSVCRT.DLL | ||
5.0 | 1100 | Visual Studio 97 | MSVCRT.DLL | MSVCP50.DLL |
6.0 | 1200 | MSVCRT.DLL | MSVCP60.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 |
15.0-15.9.11 | 1910-1916 | Visual Studio 2017 | See notes | See notes |
16.0-16.11.2 | 1920-1929 | Visual Studio 2019 | See notes | See notes |
For a discussion of the genericMSVCRT.DLL
compared to the DLLs specificto the VC version, seethis blog post.See alsothese comments on using MSVCRT.DLL from Mingw-w64.
For 2015, MS split the C runtime into two component libraries. See:
blog post on thethe 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 andglobals exported by the standard C99 CRT library. The UCRT is now a Windowscomponent, and ships as part of Windows 10.” (seeCRT 2015).vcruntime140.dll
: “The vcruntime library contains Visual C++ CRTimplementation-specific code, such as exception handling and debuggingsupport, runtime checks and type information, implementation details andcertain extended library functions. This library is specific to the versionof the compiler used.” (CRT 2015);
The C++ runtime for VS2015 isMSVCP140.dll
(CRT 2015).
The C++ runtime for VS2017 is alsoMSVCP140.dll
, but, for version 15.6,there is an additionalMSVCP140_1.dll
, ABI compatible withMSVCP140.dll
, but with additional standard library functionality; seethis MSVC page.
Visual Studio versions used to compile distributed Python binaries¶
and:http://stackoverflow.com/questions/9047072/windows-python-version-and-vc-redistributable-version
The version of Visual Studio is described inreadme.txt
in thePCBuild
folder of the source distribution. The full Visual C++ version number is ineitherrelease.vsprops
orrelease.props
. I read these files from theCPython Hg web interface for eachtagged release, up to Python 3.6, and thence, from theCPython Githubrepository.
Python version | VC++ version |
---|---|
2.5.6 | 7.1 |
2.6.9 | 9.0 |
2.7.6 | 9.0 |
3.2.3 | 9.0 |
3.3.5 | 10.0 |
3.4.0 | 10.0 |
3.5.0 | 14.0 |
3.6.0 | 14.0 |
3.7.0 | 15.0 |
3.8.0 | 15.0 |
3.9.0 | 15.0 |
3.10.0 | 15.0 |
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 athttp://aka.ms/vcpython27. I installed this for all users from acmd
Window opened with “run as administrator”, like this:
msiexec/iVCForPython27.msiALLUSERS=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 hasfinished. The compilers seem to work fine nevertheless. If this standalonePython 2.7 compiler set works for you, you should be able to compile both 32and 64 bit extensions without further configuration. If not, seeOther 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 compilePython extensions. I found that I needed to install from theoffline ISOfiles. Asyou will see in the “Install Instructions”, chooseGRMSDKX_EN_DVD.iso
for64-bit compiles.
I believe Windows 8, 10 and server 2012 can mount ISO files from explorer. ForWindows 7 / server 2008 I usedVirtual clone drive to mount the ISO files.
To run the install, navigate to the folderSetup
on the DVD image, and runSDKSetup.exe
. Otherwise you may get an error about .NET components thatcannot be installed.
Finally, for 64-bits, I needed to apply this patch to avoid a distutilscompilation error ending inValueError:['path']
:
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"
Seethis MSVC 2010 SO postfor details on installing the Windows 7.1 SDK, andthis SO answerfor specifics on the 64-bit distutils error that can be fixed with theecho
command above.
Compiling for 32-bit¶
Download and install theMSVC 2010 express edition.
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 theMSVC 2015 command line tools. Install thesefirst. To get Python to recognize the MSVC command line tools, you will needa version of thesetuptools package >= 24.0. Check by:
python-c'import setuptools; print(setuptools.__version__)'
If your version is < 24.0, then:
pipinstall--upgradesetuptools
See thePython Windows compilers wiki page for more details.
Another option is to install the wholeVS 2015 community edition. It’s ahuge 11GB install which took more than an hour on my machine. Do a custominstall, and select the VC++ compiler component (it is not selected bydefault).
Other options for MSVC installation¶
If the VS for Python 2.7 installer doesn’t work for you, or you can’t get VS2010 compilation working for 3.3 / 3.4, see the links below.
In overview, you may be able to find the free Visual Studio express downloadthat you need on the Microsoft site, but until VS 2015, these do not compile64-bit extensions by default. The instructions above give the easiest way toget 64-bit compiles working, but you can also try the other methods given inthe links below.
Some older links on installing MSVC¶
Here are some links that were useful at some point:
Cython windows wiki page.This has more on configuration for 64-bit in particular.
Somerelevant instructions from a MATLAB userfor getting the VS 2008 SDK set up (the default downloads will refuse toinstall onto VS express).