Compile CPython on Windows

See also Windows and CPython.

http://bugs.python.org/issue30350

People

People who understands these things.

  • Steve Dower: employed by Microsoft, he is the maintainer of the Windows installer for 2.7, 3.5, 3.6 and master branches
  • Zachary Ware
  • Jeremy Kloth knows the PC\VS9.0\ directory of Python 2.7!

Build a Windows VM

  • Windows 10 or newer is recommanded
  • 60 GB of disk space or more is recommanded

Python and Visual Studio version matrix

Python version Visual Studio
Python 2.7 2008 and 2010
3.5, 3.6, master 2015

Dependencies

In 2016, Perl was need to build OpenSSL. But it’s no more required.

See PCBuild/get_externals.bat.

Compile the master branch

To build the Python ssl extension:

Requirements:

  • Visual Studio 2015
  • CPython source code: get it using Git, or download a ZIP on GitHub.com

Commands:

PCbuild\build -p x64 -d -e

See also: PCbuild/readme.txt.

Compile CPython 2.7

Python 2.7 is stuck forever on Visual Studio 2008 to not break the ABI, to keep the backward compatibility with all built extensions on the Python cheeseshop (PyPI).

Compile CPython 2.7 on Windows using Visual Studio 2008 and 2010

While Visual Studio 2008 is enough to build a basic Python 2.7 binary without OpenSSL nor Tkinter, installing Visual Studio 2008 and Visual Studio 2010 is recommended to get all dependencies including Tkinter.

Requirements:

  • MSDN account to get Visual Studio 2008. Maybe it’s possible to build Python using the Express edition of VS 2008 and 2010, but in 2017, it became difficult to get VS 2008 and 2010 Express.
  • Windows 10 or newer is recommanded, even if Python 2.7 is supposed to support Windows XP!
  • Visual Studio 2008 Professional. Visual Studio 2008 Express works too, but doesn’t provide a 64-bit compiler.
  • Visual Studio 2010 Professional. Maybe a lighter flavor works, I didn’t try.
  • TortoiseSVN to get svn.exe in PATH to download Python dependencies: don’t forget to check the [x] command line tools checkbox in the installer

Compile Python in the command line:

  • Open a Visual Studio 2010 Prompt
  • In this prompt, run PCBuild\build.bat -e -d -p x64 to build Python 2.7 in debug mode for 64-bit, and install dependencies like OpenSSL, Tcl and Tk sources.

Compile Python in the IDE: open the PCbuild\pcbuild.sln solution in Visual Studio.

Compile CPython 2.7 on Windows using Visual Studio 2008

Similar to the previous section, but don’t install Visual Studio 2010: only install Visual Studio 2008.

Without Visual Studio 2010, some features don’t work, like Tkinter.

  • Project file: PCVS9.0pcbuild.sln
  • In this prompt, run VS\9.0\build.bat -e -d -p x64 to build Python 2.7 in debug mode for 64-bit, and install dependencies like OpenSSL sources if needed

Windows Subsystem for Linux: WSL

Ubuntu running on Windows 10 using a thin layer to emulate the Linux kernel on top of the Windows kernel.