Differences between revisions 20 and 21
Revision 20 as of 2015-11-13 18:08:43
Size: 8669
Editor: Jgoutin
Comment:
Revision 21 as of 2015-11-17 10:34:46
Size: 8723
Editor: Jgoutin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 110: Line 110:
 * Create a file named ''vcvarsall.bat'' in ''C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\'' containing the following text : If you want automatic use of this compiler with Python :
* Edit ''C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat'' and replace its content with the following text :

Even if Python is an interpreted language, you may need to install Windows C++ compilers in some cases. Unlike Linux, compilers for Windows are not included by default in the OS.

By example, you will need to use them if you want :

  • Install a non-pure Python package from sources with Pip (If there is no Wheel package provided).

  • Compile a Cython file.

Microsoft provide official C++ compilers called Visual C++, you can find them with Visual Studio or, for some versions, in standalone distribution. Some alternates compilers exists like MinGW, but some incompatibilities may occur with CPython official distribution which is build with Microsoft Visual C++.

The compiler architecture must be the same as Python (Example: If you use Python 64bit, you have to use a x64 compiler).

Which Microsoft Visual C++ compiler use with a specified Python version ?

Each Python version use a specific compiler version (Example : CPython 2.7 use Visual C++ 9.0, CPython 3.3 use Visual C++ 10.0, ...). So, you need to install the compiler version linked to your Python version :

Visual C++

CPython

14.0

3.5

10.0

3.3, 3.4

9.0

2.6, 2.7, 3.0, 3.1, 3.2

Compilers Installation and configuration

Compatible architectures is specified for each compiler between brackets.

This table resume architecture names correspondence:

Windows

Architecture

32Bit

x86

64Bit

x64

64Bit Itanium

ia64

Microsoft Visual C++ 14.0 standalone: Visual C++ Build Tools 2015 (x86, x64, ARM)

This is the standalone version of Visual C++ 14.0 compiler, you don't need to install Visual Studio 2015.

If you want automatic use of this compiler with Python :

  • Edit C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat and replace its content with the following text :

   1 rem Vcvarsall for Visual C++ Build Tools 2015
   2 @echo off
   3 set DISTUTILS_USE_SDK=1
   4 set MSSdk=1
   5 set vcprogramfiles=%ProgramFiles(x86)%
   6 if "%vcprogramfiles%"=="" set vcprogramfiles=%ProgramFiles%
   7 call "%vcprogramfiles%\Microsoft Visual C++ Build Tools\vcbuildtools.bat" %*

If you don't want to modify vcvarsall.bat, you have to run your commands from Visual C++ Build Tools Command Prompt (C:\Program Files (x86)\Microsoft Visual C++ Build Tools\) each time you want compile with Python.

Microsoft Visual C++ 14.0 with Visual Studio 2015 (x86, x64, ARM)

Visual Studio 2015 contain Visual C++ 14.0 compiler. Distutils will automatically detect the compiler and use it.

Microsoft Visual C++ 10.0 standalone: Windows SDK 7.1 (x86, x64, ia64)

This is the standalone version of Visual C++ 10.0 compiler, you don't need to install Visual Studio 2010.

If you want automatic use of this compiler with Python :

  • Edit C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat and replace its content with the following text :

   1 rem Vcvarsall for Windows SDK 7.1
   2 @echo off
   3 set DISTUTILS_USE_SDK=1
   4 set MSSdk=1
   5 if /i "%1" == "x64" (
   6     set vcvararch=x64
   7 ) else if /i "%1" == "amd64" (
   8     set vcvararch=x64
   9 ) else if /i "%1" == "x86_amd64" (
  10     set vcvararch=x64
  11 ) else if /i "%1" == "ia64" (
  12     set vcvararch=ia64
  13 ) else if /i "%1" == "x86_ia64" (
  14     set vcvararch=ia64
  15 ) else (
  16     set vcvararch=x86
  17 )
  18 set vcprogramfiles=%ProgramFiles(x86)%
  19 if "%vcprogramfiles%"=="" set vcprogramfiles=%ProgramFiles%
  20 call "%vcprogramfiles%\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /%vcvararch% /release

If you don't want to modify vcvarsall.bat, you have to run your commands from Windows SDK 7.1 Command Prompt (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd) each time you want compile with Python. By default, it use the x86 Debug configuration. Use /x64 or /ia64 arguments for change architecture and /Release argument for use the release configuration.

Microsoft Visual C++ 10.0 with Visual Studio 2010 (x86, x64, ia64)

Visual Studio 2010 contain Visual C++ 10.0 compiler. Distutils will automatically detect the compiler and use it.

Microsoft Visual C++ 9.0 standalone: Visual C++ Compiler for Python 2.7 (x86, x64, ia64)

This is the standalone version of Visual C++ 9.0 compiler, you don't need to install Visual Studio 2008.

pip install --upgrade setuptools

Note: Even if this compiler specify Python 2.7, you can use it with all Python versions using Visual C++ 9.0.

Microsoft Visual C++ 9.0 standalone: Windows SDK 7.0 (x86, x64, ia64)

This is the standalone version of Visual C++ 9.0 compiler, you don't need to install Visual Studio 2008.

If you want automatic use of this compiler with Python :

  • Edit C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat and replace its content with the following text :

   1 rem Vcvarsall for Windows SDK 7.0
   2 @echo off
   3 set DISTUTILS_USE_SDK=1
   4 set MSSdk=1
   5 if /i "%1" == "x64" (
   6     set vcvararch=x64
   7 ) else if /i "%1" == "amd64" (
   8     set vcvararch=x64
   9 ) else if /i "%1" == "x86_amd64" (
  10     set vcvararch=x64
  11 ) else if /i "%1" == "ia64" (
  12     set vcvararch=ia64
  13 ) else if /i "%1" == "x86_ia64" (
  14     set vcvararch=ia64
  15 ) else (
  16     set vcvararch=x86
  17 )
  18 set vcprogramfiles=%ProgramFiles(x86)%
  19 if "%vcprogramfiles%"=="" set vcprogramfiles=%ProgramFiles%
  20 call "%vcprogramfiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd" /%vcvararch% /release

If you don't want to modify vcvarsall.bat, you have to run your commands from Windows SDK 7.0 Command Prompt (C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd) each time you want compile with Python. By default, it use the x86 Debug configuration. Use /x64 or /ia64 arguments for change architecture and /Release argument for use the release configuration.

Microsoft Visual C++ 9.0 with Visual Studio 2008 (x86, x64, ia64)

Visual Studio 2008 contain Visual C++ 9.0 compiler. Distutils will automatically detect the compiler and use it.

MinGW (x86)

MinGW is an alternate C++ compiler that work with all Python versions.

  • Install Minimalist GNU For Windows in C:\MinGW.

  • Open MinGW Installation Manager, check mingw32-base and mingw32-gcc-g++, and Apply Changes in the Installation menu.

  • Add C:\MinGW\bin to PATH environment variable (With ";" before is PATH is not empty).

  • Create a distutils.cfg file with the following content in the folder \Lib\distutils in Python install directory :

   1 [build]
   2 compiler=mingw32
   3 
   4 [build_ext]
   5 compiler=mingw32

Links

WindowsCompilers (last edited 2023-06-09 12:03:05 by MarcAndreLemburg)

Unable to edit the page? See the FrontPage for instructions.