blob: d5ef00f7805cfb28f7331f3cd38b31bdbc12d096 [file] [log] [blame]
Zachary Waree12fa652014-07-07 13:39:59 -05001Quick Start Guide
2-----------------
3
41. Install Microsoft Visual C++ 2010 SP1, any edition.
52. Install Subversion, and make sure 'svn.exe' is on your PATH.
63. Install NASM, and make sure 'nasm.exe' is on your PATH.
74. Run "build.bat -e" to build Python in 32-bit Release configuration.
85. (Optional, but recommended) Run the test suite with "rt.bat -q".
9
10
Tim Golden7d052362013-10-25 08:58:16 +010011Building Python using Microsoft Visual C++
12------------------------------------------
Christian Heimes57dddfb2008-01-02 18:30:52 +000013
Tim Golden7d052362013-10-25 08:58:16 +010014This directory is used to build CPython for Microsoft Windows NT version
155.1 or higher (Windows XP, Windows Server 2003, or later) on 32 and 64
16bit platforms. Using this directory requires an installation of
17Microsoft Visual C++ 2010 (MSVC 10.0) of any edition. The specific
18requirements are as follows:
Zachary Ware5f3e3c32014-03-19 14:46:25 -050019
Tim Golden7d052362013-10-25 08:58:16 +010020Visual C++ 2010 Express Edition
21 Required for building 32-bit Debug and Release configuration builds.
Zachary Wareef035652014-07-07 14:33:24 -050022 The Python build solution pcbuild.sln makes use of Solution Folders,
23 which this edition does not support. Any time pcbuild.sln is opened
24 or reloaded by Visual C++, a warning about Solution Folders will be
25 displayed which can be safely dismissed with no impact on your
26 ability to build Python.
Tim Golden7d052362013-10-25 08:58:16 +010027Visual Studio 2010 Professional Edition
Zachary Ware5f3e3c32014-03-19 14:46:25 -050028 Required for building 64-bit Debug and Release configuration builds
29Visual Studio 2010 Premium Edition
Tim Golden7d052362013-10-25 08:58:16 +010030 Required for building Release configuration builds that make use of
Zachary Ware5f3e3c32014-03-19 14:46:25 -050031 Profile Guided Optimization (PGO), on either platform.
32
Zachary Ware4856a6a2014-06-13 09:38:50 -050033Installing Service Pack 1 for Visual Studio 2010 is highly recommended
34to avoid LNK1123 errors.
35
Tim Golden7d052362013-10-25 08:58:16 +010036All you need to do to build is open the solution "pcbuild.sln" in Visual
37Studio, select the desired combination of configuration and platform,
38then build with "Build Solution" or the F7 keyboard shortcut. You can
39also build from the command line using the "build.bat" script in this
Zachary Waree12fa652014-07-07 13:39:59 -050040directory; see below for details. The solution is configured to build
41the projects in the correct order.
Guido van Rossum15b239f1998-05-26 14:16:23 +000042
Tim Golden7d052362013-10-25 08:58:16 +010043The solution currently supports two platforms. The Win32 platform is
44used to build standard x86-compatible 32-bit binaries, output into this
45directory. The x64 platform is used for building 64-bit AMD64 (aka
46x86_64 or EM64T) binaries, output into the amd64 sub-directory which
47will be created if it doesn't already exist. The Itanium (IA-64)
48platform is no longer supported. See the "Building for AMD64" section
49below for more information about 64-bit builds.
Guido van Rossum15b239f1998-05-26 14:16:23 +000050
Tim Golden7d052362013-10-25 08:58:16 +010051Four configuration options are supported by the solution:
52Debug
53 Used to build Python with extra debugging capabilities, equivalent
54 to using ./configure --with-pydebug on UNIX. All binaries built
55 using this configuration have "_d" added to their name:
Zachary Ware6373ba52014-03-17 15:57:38 -050056 python35_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
Tim Golden7d052362013-10-25 08:58:16 +010057 build and rt (run test) batch files in this directory accept a -d
58 option for debug builds. If you are building Python to help with
59 development of CPython, you will most likely use this configuration.
60PGInstrument, PGUpdate
61 Used to build Python in Release configuration using PGO, which
Zachary Ware2170b142014-07-07 14:31:34 -050062 requires Premium Edition of Visual Studio. See the "Profile
Tim Golden7d052362013-10-25 08:58:16 +010063 Guided Optimization" section below for more information. Build
64 output from each of these configurations lands in its own
65 sub-directory of this directory. The official Python releases are
66 built using these configurations.
67Release
68 Used to build Python as it is meant to be used in production
69 settings, though without PGO.
Guido van Rossum15b239f1998-05-26 14:16:23 +000070
Christian Heimes5b5e81c2007-12-31 16:14:33 +000071
Zachary Waree12fa652014-07-07 13:39:59 -050072Building Python using the build.bat script
73----------------------------------------------
74
75In this directory you can find build.bat, a script designed to make
76building Python on Windows simpler. The only absolute requirement for
77using this script is for the VS100COMNTOOLS environment variable to be
78properly set, which should be done by Microsoft Visual C++ 2010
79installation.
80
81By default, build.bat will build Python in Release configuration for
82the 32-bit Win32 platform. It accepts several arguments to change
83this behavior:
84
85 -c <configuration> Set the configuration (see above)
86 -d Shortcut for "-c Debug"
87 -p <platform> Set the platform to build for ("Win32" or "x64")
88 -r Rebuild instead of just building
89 -e Use get_externals.bat to fetch external sources
90
91
Christian Heimes57dddfb2008-01-02 18:30:52 +000092Legacy support
93--------------
94
Tim Golden7d052362013-10-25 08:58:16 +010095You can find build directories for older versions of Visual Studio and
96Visual C++ in the PC directory. The legacy build directories are no
97longer actively maintained and may not work out of the box.
Christian Heimes57dddfb2008-01-02 18:30:52 +000098
Tim Golden7d052362013-10-25 08:58:16 +010099Currently, the only legacy build directory is PC\VS9.0, for Visual
100Studio 2008 (9.0).
Christian Heimes57dddfb2008-01-02 18:30:52 +0000101
102
Tim Golden7d052362013-10-25 08:58:16 +0100103C Runtime
Christian Heimes57dddfb2008-01-02 18:30:52 +0000104---------
105
Tim Golden7d052362013-10-25 08:58:16 +0100106Visual Studio 2010 uses version 10 of the C runtime (MSVCRT10). The
107executables no longer use the "Side by Side" assemblies used in previous
108versions of the compiler. This simplifies distribution of applications.
Christian Heimes57dddfb2008-01-02 18:30:52 +0000109
Tim Golden7d052362013-10-25 08:58:16 +0100110The run time libraries are available under the VC/Redist folder of your
111Visual Studio distribution. For more info, see the Readme in the
112VC/Redist folder.
Guido van Rossume79cf321998-07-07 22:35:03 +0000113
Tim Golden7d052362013-10-25 08:58:16 +0100114
115Sub-Projects
116------------
117
118The CPython project is split up into several smaller sub-projects which
119are managed by the pcbuild.sln solution file. Each sub-project is
120represented by a .vcxproj and a .vcxproj.filters file starting with the
121name of the sub-project. These sub-projects fall into a few general
122categories:
123
124The following sub-projects represent the bare minimum required to build
125a functioning CPython interpreter. If nothing else builds but these,
126you'll have a very limited but usable python.exe:
Tim Peters97c96402001-01-17 23:23:13 +0000127pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +0000128 .dll and .lib
129python
130 .exe
Tim Golden7d052362013-10-25 08:58:16 +0100131kill_python
132 kill_python.exe, a small program designed to kill any instances of
133 python(_d).exe that are running and live in the build output
134 directory; this is meant to avoid build issues due to locked files
135make_buildinfo, make_versioninfo
136 helpers to provide necessary information to the build process
137
138These sub-projects provide extra executables that are useful for running
139CPython in different ways:
Tim Peters4b5fb072000-07-01 00:03:43 +0000140pythonw
Tim Golden7d052362013-10-25 08:58:16 +0100141 pythonw.exe, a variant of python.exe that doesn't open a Command
142 Prompt window
143pylauncher
144 py.exe, the Python Launcher for Windows, see
145 http://docs.python.org/3/using/windows.html#launcher
146pywlauncher
147 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
148 window
Zachary Waree0881f42013-11-05 21:55:46 -0600149_testembed
150 _testembed.exe, a small program that embeds Python for testing
151 purposes, used by test_capi.py
Tim Golden7d052362013-10-25 08:58:16 +0100152
153These are miscellaneous sub-projects that don't really fit the other
154categories. By default, these projects do not build in Debug
155configuration:
156_freeze_importlib
157 _freeze_importlib.exe, used to regenerate Python\importlib.h after
158 changes have been made to Lib\importlib\_bootstrap.py
159bdist_wininst
160 ..\Lib\distutils\command\wininst-10.0[-amd64].exe, the base
161 executable used by the distutils bdist_wininst command
162python3dll
163 python3.dll, the PEP 384 Stable ABI dll
164xxlimited
165 builds an example module that makes use of the PEP 384 Stable ABI,
166 see Modules\xxlimited.c
167
168The following sub-projects are for individual modules of the standard
169library which are implemented in C; each one builds a DLL (renamed to
170.pyd) of the same name as the project:
171_ctypes
172_ctypes_test
173_decimal
174_elementtree
175_hashlib
176_msi
177_multiprocessing
178_overlapped
Tim Peters4b5fb072000-07-01 00:03:43 +0000179_socket
Tim Petersd66595f2001-02-04 03:09:53 +0000180_testcapi
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100181_testbuffer
Tim Golden7d052362013-10-25 08:58:16 +0100182_testimportmultiple
Tim Petersb012a152002-02-13 23:56:46 +0000183pyexpat
Tim Peters4b5fb072000-07-01 00:03:43 +0000184select
Tim Peters19f52c22001-01-24 10:07:22 +0000185unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +0000186winsound
Tim Peters4b5fb072000-07-01 00:03:43 +0000187
Tim Golden7d052362013-10-25 08:58:16 +0100188The following Python-controlled sub-projects wrap external projects.
189Note that these external libraries are not necessary for a working
190interpreter, but they do implement several major features. See the
191"Getting External Sources" section below for additional information
192about getting the source for building these libraries. The sub-projects
193are:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200194_bz2
Tim Golden7d052362013-10-25 08:58:16 +0100195 Python wrapper for version 1.0.6 of the libbzip2 compression library
196 Homepage:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200197 http://www.bzip.org/
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200198_lzma
Tim Golden7d052362013-10-25 08:58:16 +0100199 Python wrapper for the liblzma compression library, using pre-built
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100200 binaries of XZ Utils version 5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100201 Homepage:
202 http://tukaani.org/xz/
Mark Hammondf229f9f2002-12-03 05:47:26 +0000203_ssl
Zachary Ware7d55da42014-06-06 01:23:53 -0500204 Python wrapper for version 1.0.1h of the OpenSSL secure sockets
Tim Golden7d052362013-10-25 08:58:16 +0100205 library, which is built by ssl.vcxproj
206 Homepage:
207 http://www.openssl.org/
Tim Peters4b5fb072000-07-01 00:03:43 +0000208
Tim Golden7d052362013-10-25 08:58:16 +0100209 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
210 2.10 or newer from
211 http://www.nasm.us/
212 to be somewhere on your PATH. More recent versions of OpenSSL may
213 need a later version of NASM. If OpenSSL's self tests don't pass,
214 you should first try to update NASM and do a full rebuild of
215 OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000216
Zachary Ware10c2dba2014-05-09 09:07:50 -0500217 The ssl sub-project expects your OpenSSL sources to have already
218 been configured and be ready to build. If you get your sources
219 from svn.python.org as suggested in the "Getting External Sources"
220 section below, the OpenSSL source will already be ready to go. If
221 you want to build a different version, you will need to run
222
223 PCbuild\prepare_ssl.py path\to\openssl-source-dir
224
225 That script will prepare your OpenSSL sources in the same way that
226 those available on svn.python.org have been prepared. Note that
227 Perl must be installed and available on your PATH to configure
228 OpenSSL. ActivePerl is recommended and is available from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000229 http://www.activestate.com/activeperl/
Mark Hammondf229f9f2002-12-03 05:47:26 +0000230
Tim Golden7d052362013-10-25 08:58:16 +0100231 The ssl sub-project does not have the ability to clean the OpenSSL
232 build; if you need to rebuild, you'll have to clean it by hand.
233_sqlite3
Martin v. Löwis09257f72014-03-02 19:42:50 +0100234 Wraps SQLite 3.8.3.1, which is itself built by sqlite3.vcxproj
Tim Golden7d052362013-10-25 08:58:16 +0100235 Homepage:
236 http://www.sqlite.org/
237_tkinter
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100238 Wraps version 8.6.1 of the Tk windowing system.
Tim Golden7d052362013-10-25 08:58:16 +0100239 Homepage:
240 http://www.tcl.tk/
Tim Peters4b5fb072000-07-01 00:03:43 +0000241
Zachary Warea191b912014-03-21 22:58:19 -0500242 Tkinter's dependencies are built by the tcl.vcxproj and tk.vcxproj
243 projects. The tix.vcxproj project also builds the Tix extended
244 widget set for use with Tkinter.
245
246 Those three projects install their respective components in a
247 directory alongside the source directories called "tcltk" on
248 Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs
249 into the current output directory, which should ensure that Tkinter
250 is able to load Tcl/Tk without having to change your PATH.
251
252 The tcl, tk, and tix sub-projects do not have the ability to clean
253 their builds; if you need to rebuild, you'll have to clean them by
254 hand.
Trent Nelson52037272008-04-02 15:06:49 +0000255
Trent Nelson52037272008-04-02 15:06:49 +0000256
Tim Golden7d052362013-10-25 08:58:16 +0100257Getting External Sources
258------------------------
259
260The last category of sub-projects listed above wrap external projects
261Python doesn't control, and as such a little more work is required in
262order to download the relevant source files for each project before they
Zachary Waree12fa652014-07-07 13:39:59 -0500263can be built. However, a simple script is provided to make this as
264painless as possible, called "get_externals.bat" and located in this
265directory. This script extracts all the external sub-projects from
Tim Golden7d052362013-10-25 08:58:16 +0100266 http://svn.python.org/projects/external
Zachary Waree12fa652014-07-07 13:39:59 -0500267via Subversion (so you'll need svn.exe on your PATH) and places them
Tim Golden7d052362013-10-25 08:58:16 +0100268in ..\.. (relative to this directory).
269
270It is also possible to download sources from each project's homepage,
Zachary Waree12fa652014-07-07 13:39:59 -0500271though you may have to change folder names or pass the names to MSBuild
272as the values of certain properties in order for the build solution to
273find them. This is an advanced topic and not necessarily fully
274supported.
Tim Golden7d052362013-10-25 08:58:16 +0100275
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000276
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000277Building for AMD64
278------------------
279
Tim Golden7d052362013-10-25 08:58:16 +0100280The build process for AMD64 / x64 is very similar to standard builds,
281you just have to set x64 as platform. In addition, the HOST_PYTHON
282environment variable must point to a Python interpreter (at least 2.4),
283to support cross-compilation from Win32. Note that Visual Studio
Zachary Waree08f3762014-03-28 23:31:04 -0500284requires Professional Edition or better in order to build 64-bit
Tim Golden7d052362013-10-25 08:58:16 +0100285binaries.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000286
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000287
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000288Profile Guided Optimization
289---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000290
Christian Heimes25bb7832008-01-11 16:17:00 +0000291The solution has two configurations for PGO. The PGInstrument
Tim Golden7d052362013-10-25 08:58:16 +0100292configuration must be built first. The PGInstrument binaries are linked
293against a profiling library and contain extra debug information. The
294PGUpdate configuration takes the profiling data and generates optimized
295binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000296
Tim Golden7d052362013-10-25 08:58:16 +0100297The build_pgo.bat script automates the creation of optimized binaries.
298It creates the PGI files, runs the unit test suite or PyBench with the
299PGI python, and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000300
Tim Golden7d052362013-10-25 08:58:16 +0100301See
302 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
303for more on this topic.
304
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000305
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000306Static library
307--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000308
Tim Golden7d052362013-10-25 08:58:16 +0100309The solution has no configuration for static libraries. However it is
310easy to build a static library instead of a DLL. You simply have to set
311the "Configuration Type" to "Static Library (.lib)" and alter the
312preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
313also have to change the "Runtime Library" from "Multi-threaded DLL
314(/MD)" to "Multi-threaded (/MT)".
315
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000316
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000317Visual Studio properties
318------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000319
Tim Golden7d052362013-10-25 08:58:16 +0100320The PCbuild solution makes heavy use of Visual Studio property files
321(*.props). The properties can be viewed and altered in the Property
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000322Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000323
Tim Golden7d052362013-10-25 08:58:16 +0100324The property files used are (+-- = "also imports"):
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000325 * debug (debug macro: _DEBUG)
326 * pginstrument (PGO)
327 * pgupdate (PGO)
328 +-- pginstrument
329 * pyd (python extension, release build)
330 +-- release
331 +-- pyproject
332 * pyd_d (python extension, debug build)
333 +-- debug
334 +-- pyproject
335 * pyproject (base settings for all projects, user macros like PyDllName)
336 * release (release macro: NDEBUG)
Tim Golden7d052362013-10-25 08:58:16 +0100337 * sqlite3 (used only by sqlite3.vcxproj)
Zachary Ware4b87dc62014-03-28 23:36:43 -0500338 * tcltk (used by _tkinter, tcl, tk and tix projects)
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000339 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000340
Tim Golden7d052362013-10-25 08:58:16 +0100341The pyproject property file defines _WIN32 and x64 defines _WIN64 and
342_M_X64 although the macros are set by the compiler, too. The GUI doesn't
343always know about the macros and confuse the user with false
344information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000345
Tim Golden7d052362013-10-25 08:58:16 +0100346
347Your Own Extension DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000348-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000349
Tim Golden7d052362013-10-25 08:58:16 +0100350If you want to create your own extension module DLL (.pyd), there's an
351example with easy-to-follow instructions in ..\PC\example\; read the
352file readme.txt there first.