What version of Visual Studio is Python on my computer compiled with?
Visual C++ version | _MSC_VER |
---|---|
Visual C++ 4.x | 1000 |
Visual C++ 5 | 1100 |
Visual C++ 6 | 1200 |
Visual C++ .NET | 1300 |
Visual C++ .NET 2003 | 1310 |
Visual C++ 2005 (8.0) | 1400 |
Visual C++ 2008 (9.0) | 1500 |
Visual C++ 2010 (10.0) | 1600 |
Visual C++ 2012 (11.0) | 1700 |
Visual C++ 2013 (12.0) | 1800 |
Visual C++ 2015 (14.0) | 1900 |
Visual C++ 2017 (15.0) | 1910 |
Visual C++ 2017 (15.3) | 1911 |
Visual C++ 2017 (15.5) | 1912 |
Visual C++ 2017 (15.6) | 1913 |
Visual C++ 2017 (15.7) | 1914 |
Visual C++ 2017 (15.8) | 1915 |
Visual C++ 2017 (15.9) | 1916 |
Visual C++ 2019 RTW (16.0) | 1920 |
Visual C++ 2019 (16.1) | 1921 |
Visual C++ 2019 (16.2) | 1922 |
Visual C++ 2019 (16.3) | 1923 |
Visual C++ 2019 (16.4) | 1924 |
Visual C++ 2019 (16.5) | 1925 |
Visual C++ 2019 (16.6) | 1926 |
Visual C++ 2019 (16.7) | 1927 |
Visual C++ 2019 (16.8) | 1928 |
Visual C++ 2019 (16.9) | 1928 |
Visual C++ 2019 (16.10) | 1929 |
Visual C++ 2019 (16.11) | 1929 |
Visual Studio 2022 RTW (17.0) | 1930 |
What version of Visual Studio and/or MinGW do I need to build extension modules for a given version of Python?
The file PCbuild\readme.txt
in the source distribution of each version of Python includes the version of Visual Studio used to make the binaries.
Python 2.6, 2.7, 3.1, and 3.2 were all compiled with VS 2008. Python 3.3 and 3.4 are compiled with VS 2010.
I'm not sure about MinGW compatibility.
If you are looking for command line compilers, Microsoft has released two different SDKs for Windows 7 that include the command line compilers. The first SDK (for .NET 3.5) includes the VS 2008 compilers. The second SDK (for .NET 4.0) includes the VS 2010 compilers.
Update: The file PCbuild\readme.txt
in the source distribution of each version of Python includes the version of Visual Studio used to make the binaries.
Windows Python Version and VC++ Redistributable Version
Python 2.5 links against msvcr71 just like 2.4. Versions 2.6 and 2.7 link against msvcr90 which is the VS2008 runtime. In fact versions 3.0, 3.1 and 3.2 also link against msvcr90.
The msvcr90 redistributable is here: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=29
Python was not found but can be installed from the Microsoft store (March, 2020)
You don't have the command python
installed into your PATH
on Windows which is the default if you didn't get your copy of Python from the Windows Store. If you selected your Python interpreter in VS Code (look in the status bar), then I would disable Code Runner. That way the Python extension is what provides the ability to run Python (the Play button will be green instead of white).
Microsoft Visual C++ Compiler for Python 3.4
Unfortunately to be able to use the extension modules provided by others you'll be forced to use the official compiler to compile Python. These are:
Visual Studio 2008 for Python 2.7.
See: https://docs.python.org/2.7/using/windows.html#compiling-python-on-windowsVisual Studio 2010 for Python 3.4.
See: https://docs.python.org/3.4/using/windows.html#compiling-python-on-windows
Alternatively, you can use MinGw to compile extensions in a way that won't depend on others.
See: https://docs.python.org/2/install/#gnu-c-cygwin-MinGW or https://docs.python.org/3.4/install/#gnu-c-cygwin-mingw
This allows you to have one compiler to build your extensions for both versions of Python, Python 2.x and Python 3.x.
Compiling Python modules on Windows x64
Update: This answer is now over 5 years old! Python-2.7 is about to be deprecated, so what you really need is a Microsoft Visual C compiler for Python-3. Take a look at this Python wiki on MS Windows Compilers. MS Build Tools 2015 with VC-14.0 is what you need to build extensions for Python-3.5 and 3.6. You can either install the older MS build tools 2015 which includes VC-14.0 or the newer MS build tools for 2017 - click the link, then scroll down until you find Build Tools for Visual Studio 2017 - which also includes VC-14.0.
Also if your versions of pip and setuptools are up to date, then you can ignore all of that silly old school MSSDK nonsense. Especially if you are using the VC for Python 2.7 or MS build tools 2015. Since setuptools-24, it just knows where to look for these compilers, hopefully.
Update: As Zooba mentions below, free x86 and AMD64 (x86-64) VC90 c-compilers for Python-2.7 are now available from Microsoft.
Update: Patch vcvarsall.bat
to use x64 compilers from SDK v7.0 directly with pip
in any shell instead of using SDK shell and setting DISTUTILS_USE_SDK
and MSSdk
environmental variables as in directions below. See Fix vcvarsall.bat to install Python-2.7 x64 extensions with v90 instead of sdk7.
tl;dr: Use Windows SDK v7.0 compilers, open the SDK shell and call
C:\> setenv /release /x64
C:\> set DISTUTILS_USE_SDK=1
C:\> MSSdk=1
to build Python 2.7.x extensions using distutils, pip
or easy_install
. See Python x64 Package Extensions with pip, MSVC 2008 Express & SDK 7.
Note: You can install Numpy optimized using Intel MKL from Christoph Gohlke. For virtualenv's, try converting the binary distribution windows installer to a wheel file which can be installed with pip. Building NumPy from source is not trivial. It has become a possibility with the recent introduction and availability of OpenBLAS, a fork of GotoBLAS. There are optimized binaries available for Windows x86 and x86-64 as well as source which is relatively simpler to compile than GotoBLAS or ATLAS.
Note: In the past I hadn't recommended compiling NumPy from source because you had to optimize BLAS for your platform which was very time-intensive, and the reference BLAS (FORTRAN) or CBLAS (C/C++) implementations were relatively low-performing. Also NumPy depends on LAPACK which also depends on BLAS an additional hurdle to building NumPy. However OpenBLAS binaries are already compiled with LAPACK, so this obstacle has already been removed. See Carl Kleffner's static MinGW-w64 toolchains to build NumPy with OpenBLAS on Windows - he has resolved some of the ABI incompatibilities and issues linking to the correct Microsoft Visual C Common Runtime library (msvcr90.dll
for Python-2.7).
So onward to the main question about installing Python extensions on Windows 7 x64.
The recommended way to compile extensions is to use the same compiler used to compile the Python shared library [1-3]. The official Python 2.7.x for Windows was compiled using Microsoft Visual C++ Compilers version 9.0 [4] (aka MSVC90 or simply VC90) from Microsoft Visual Studio 2008 Professional, which you might be able to get for free from Microsoft DreamSpark. Evidentally the x64 compilers are not installed by default, so make sure they are installed along with the x86 compilers. Note: MS Visual Studio 2008 may no longer be available, but MS Visual Studio 2010 will let you use the MSVC90 toolchain if installed, which can be installed from Windows SDK7.
You can tell what version your Python was built with by looking at the header when you execute the python interpreter from a command line. e.g.: Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
means that it was built with VS 2008 C++. You can build Python yourself from source, but this is also an arduous task. In general it is not recommended to mix compiler runtimes, although in practice you may find that they still work.
If you have your heart set on using GNU GCC, then you would have to use mingw-w64 because MinGW is only for native x86 applications, not AMD64/x86-64. You will need to
- create a distutils config file to specify the mingw compiler,
- remove the -mno-cygwin bug from distutils.cygwinccompiler.Mingw32ccompiler and
- export a library definitions file using either
pexports.exe
from msys orgendef.exe
from msys2 and make a static librarylibpython27.a
usingdlltool.exe
(msys/msys2) (but the newest releases of Official Python for Windows already have this file in thePython27\lib
folder, thanks!).
However in the end you will still need to link against the runtime that python was built with, msvcr90.dll
, so you will need Visual C++ 2008 redistributable. Note: Windows GCC from mingw-w64 uses msvcrt.dll
which is not the same as msvcr90.dll
or later.
If you want to do it for free you can use Microsoft Visual C++ 2008 Express SP1 but you will need to add the Windows SDK 7 for .NET Frameworks 3.5 SP1 because the express version does not have the x64 compilers. The procedure for installing x64 C++ extensions with VS2008 Express & SDK 7 are very similar to the those on the cython site for windows x64 extensions. Note: MS Visual Studio 2008 Express is no longer available or supported.
FYI: You do not necessarily need Visual Studio to build using Microsoft compilers. They are available free with the appropriate SDK package. CL.EXE
is the compiler executable, but you will have to set whatever platform options that are normally configured by Autotools or some other tool such as CMAKE. CMAKE plays well with MSVC, but Autotools AFAIK doesn't work with MSVC and would require some POSIX environment and utilities which on Windows are available in MSYS.
For many Python packages that use distutils or setuptools, they can compile extensions using Windows SDK 7 by following the directions that are posted in various places through the reference documentation and wikis:
- From the Start Menu select All Programs then Microsoft Windows SDK v7.0 and start CMD Shell to open a command window optimized for Windows SDK.
Step #1 is the equivalent of typing the following in the Run box from the Start Menu or from a Command Prompt (aka
C:\Windows\System32\cmd.exe
):%COMSPEC% /E:ON /V:ON /K "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd"
NOTE: The flags
/E:ON
, which enables command extensions, and/V:ON
, which enables delayed variable expansion, are both necessary to forSetEnv.cmd
to function, or you will get an message that the x64 compilers are not installed, &c.Then type
setenv /Release /x64
which will set the SDK environment variables specifically for Windows 7 x64 release (vs debug or x86 which are the default).- Type
set DISTUTILS_USE_SDK=1
hit return and then typeset MSSdk=1
and return to telldistutils.msvccompiler
that you are using the SDK, and that the SDK will determine all of the environment variables. - Now use your installation method of choice:
pip install pyyaml ntlk
which is the recommended way, see ntlk, but you must have setuptools and pip installed.python setup.py install
for each downloaded, extracted tarballeasy_install pyyaml ntlk
which is the old way and the only way to install eggs.
[1] Building C and C++ Extensions on Windows
[2] distutils.msvccompiler — Microsoft Compiler
[3] Python Dev Guide: Getting Started: Windows
[4] What version of visual studio is this python compiled with
VSCode: The term 'python' is not recognized...but py works
It turned out that I just had to restart my computer after I installed ms-python.python
and tht13.python
and formulahendry.code-runner
extensions on the VS Code and added python's Scripts
folder in PATH
.
Now both py
and python
commands work from anywhere like cmd
or Run Code
in the right click menu.
Related Topics
Why the Global Interpreter Lock
Getting Started with the Python Debugger, Pdb
Speed of Calculating Powers (In Python)
Converting an Rgb Color Tuple to a Hexidecimal String
How to Use Groupby to Concatenate Strings in Python Pandas
Syntaxerror Inconsistency in Python
How to Randomly Choose a Maths Operator and Ask Recurring Maths Questions with It
Scipy: Savefig Without Frames, Axes, Only Content
Python's JSON Module, Converts Int Dictionary Keys to Strings
Numpy - Create Matrix with Rows of Vector
Count Number of Non-Nan Entries in Each Column of Spark Dataframe with Pyspark
How to Patch a Python Decorator Before It Wraps a Function
How to Make Urllib2 Requests Through Tor in Python
How to Bundle Other Files When Using Cx_Freeze
How to Include Related Model Fields Using Django Rest Framework