blob: b806f336b8aeb420c9b1cbf2a9d7bdd25bd402b7 [file] [log] [blame]
Zachary Ware6b6e6872017-06-10 14:58:42 -05001Quick Start Guide
2-----------------
3
Steve Dowerbab21fa2017-09-07 20:10:29 -070041. Install Microsoft Visual Studio 2017 with Python workload and
5 Python native development component.
Zachary Ware51599e22017-06-15 22:08:51 -050061a. Optionally install Python 3.6 or later. If not installed,
Steve Dowerbab21fa2017-09-07 20:10:29 -07007 get_externals.bat (via build.bat) will download and use Python via
Zachary Ware51599e22017-06-15 22:08:51 -05008 NuGet.
Steve Dowerbab21fa2017-09-07 20:10:29 -070092. Run "build.bat" to build Python in 32-bit Release configuration.
Zachary Ware51599e22017-06-15 22:08:51 -0500103. (Optional, but recommended) Run the test suite with "rt.bat -q".
Zachary Ware6b6e6872017-06-10 14:58:42 -050011
12
13Building Python using Microsoft Visual C++
14------------------------------------------
15
16This directory is used to build CPython for Microsoft Windows NT version
176.0 or higher (Windows Vista, Windows Server 2008, or later) on 32 and 64
18bit platforms. Using this directory requires an installation of
Steve Dowerbab21fa2017-09-07 20:10:29 -070019Microsoft Visual Studio 2017 (MSVC 14.1) with the *Python workload* and
20its optional *Python native development* component selected. (For
21command-line builds, Visual Studio 2015 may also be used.)
Zachary Ware6b6e6872017-06-10 14:58:42 -050022
Steve Dowerbab21fa2017-09-07 20:10:29 -070023Building from the command line is recommended in order to obtain any
24external dependencies. To build, simply run the "build.bat" script without
25any arguments. After this succeeds, you can open the "pcbuild.sln"
26solution in Visual Studio to continue development.
Zachary Ware6b6e6872017-06-10 14:58:42 -050027
28The solution currently supports two platforms. The Win32 platform is
29used to build standard x86-compatible 32-bit binaries, output into the
30win32 sub-directory. The x64 platform is used for building 64-bit AMD64
31(aka x86_64 or EM64T) binaries, output into the amd64 sub-directory.
32The Itanium (IA-64) platform is no longer supported.
33
34Four configuration options are supported by the solution:
35Debug
36 Used to build Python with extra debugging capabilities, equivalent
37 to using ./configure --with-pydebug on UNIX. All binaries built
38 using this configuration have "_d" added to their name:
39 python37_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
40 build and rt (run test) batch files in this directory accept a -d
41 option for debug builds. If you are building Python to help with
42 development of CPython, you will most likely use this configuration.
43PGInstrument, PGUpdate
44 Used to build Python in Release configuration using PGO, which
45 requires Premium Edition of Visual Studio. See the "Profile
46 Guided Optimization" section below for more information. Build
47 output from each of these configurations lands in its own
48 sub-directory of this directory. The official Python releases may
49 be built using these configurations.
50Release
51 Used to build Python as it is meant to be used in production
52 settings, though without PGO.
53
54
55Building Python using the build.bat script
56----------------------------------------------
57
58In this directory you can find build.bat, a script designed to make
59building Python on Windows simpler. This script will use the env.bat
Steve Dowerbab21fa2017-09-07 20:10:29 -070060script to detect either Visual Studio 2017 or 2015, either of
61which may be used to build Python. Currently Visual Studio 2017 is
Zachary Ware6b6e6872017-06-10 14:58:42 -050062officially supported.
63
64By default, build.bat will build Python in Release configuration for
65the 32-bit Win32 platform. It accepts several arguments to change
66this behavior, try `build.bat -h` to learn more.
67
68
69C Runtime
70---------
71
Steve Dowerbab21fa2017-09-07 20:10:29 -070072Visual Studio 2017 uses version 14.0 of the C runtime (vcruntime140).
73The executables no longer use the "Side by Side" assemblies used in
74previous versions of the compiler. This simplifies distribution of
75applications.
Zachary Ware6b6e6872017-06-10 14:58:42 -050076
Steve Dowerbab21fa2017-09-07 20:10:29 -070077The run time libraries are available under the redist folder of your
Zachary Ware6b6e6872017-06-10 14:58:42 -050078Visual Studio distribution. For more info, see the Readme in the
Steve Dowerbab21fa2017-09-07 20:10:29 -070079redist folder.
Zachary Ware6b6e6872017-06-10 14:58:42 -050080
81
82Sub-Projects
83------------
84
85The CPython project is split up into several smaller sub-projects which
86are managed by the pcbuild.sln solution file. Each sub-project is
87represented by a .vcxproj and a .vcxproj.filters file starting with the
88name of the sub-project. These sub-projects fall into a few general
89categories:
90
91The following sub-projects represent the bare minimum required to build
92a functioning CPython interpreter. If nothing else builds but these,
93you'll have a very limited but usable python.exe:
94pythoncore
95 .dll and .lib
96python
97 .exe
98
99These sub-projects provide extra executables that are useful for running
100CPython in different ways:
101pythonw
102 pythonw.exe, a variant of python.exe that doesn't open a Command
103 Prompt window
104pylauncher
105 py.exe, the Python Launcher for Windows, see
106 http://docs.python.org/3/using/windows.html#launcher
107pywlauncher
108 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
109 window
110_testembed
111 _testembed.exe, a small program that embeds Python for testing
112 purposes, used by test_capi.py
113
114These are miscellaneous sub-projects that don't really fit the other
115categories:
116_freeze_importlib
117 _freeze_importlib.exe, used to regenerate Python\importlib.h after
118 changes have been made to Lib\importlib\_bootstrap.py
Steve Dowerbab21fa2017-09-07 20:10:29 -0700119pyshellext
120 pyshellext.dll, the shell extension deployed with the launcher
Zachary Ware6b6e6872017-06-10 14:58:42 -0500121python3dll
122 python3.dll, the PEP 384 Stable ABI dll
123xxlimited
124 builds an example module that makes use of the PEP 384 Stable ABI,
125 see Modules\xxlimited.c
126
127The following sub-projects are for individual modules of the standard
128library which are implemented in C; each one builds a DLL (renamed to
129.pyd) of the same name as the project:
Steve Dowerbab21fa2017-09-07 20:10:29 -0700130_asyncio
Zachary Ware6b6e6872017-06-10 14:58:42 -0500131_ctypes
132_ctypes_test
133_decimal
134_elementtree
135_hashlib
136_msi
137_multiprocessing
138_overlapped
139_socket
Zachary Ware6b6e6872017-06-10 14:58:42 -0500140_testbuffer
Steve Dowerbab21fa2017-09-07 20:10:29 -0700141_testcapi
142_testconsole
Zachary Ware6b6e6872017-06-10 14:58:42 -0500143_testimportmultiple
Steve Dowerbab21fa2017-09-07 20:10:29 -0700144_testmultiphase
145_tkinter
Zachary Ware6b6e6872017-06-10 14:58:42 -0500146pyexpat
147select
148unicodedata
149winsound
150
151The following Python-controlled sub-projects wrap external projects.
152Note that these external libraries are not necessary for a working
153interpreter, but they do implement several major features. See the
154"Getting External Sources" section below for additional information
155about getting the source for building these libraries. The sub-projects
156are:
157_bz2
158 Python wrapper for version 1.0.6 of the libbzip2 compression library
159 Homepage:
160 http://www.bzip.org/
161_lzma
Zachary Ware51599e22017-06-15 22:08:51 -0500162 Python wrapper for version 5.2.2 of the liblzma compression library
Zachary Ware6b6e6872017-06-10 14:58:42 -0500163 Homepage:
164 http://tukaani.org/xz/
165_ssl
166 Python wrapper for version 1.0.2k of the OpenSSL secure sockets
Steve Dowerbab21fa2017-09-07 20:10:29 -0700167 library, which is downloaded from our binaries repository at
168 https://github.com/python/cpython-bin-deps.
169
Zachary Ware6b6e6872017-06-10 14:58:42 -0500170 Homepage:
171 http://www.openssl.org/
172
Steve Dowerbab21fa2017-09-07 20:10:29 -0700173 Building OpenSSL requires Perl on your path, and can be performed by
174 running PCbuild\prepare_ssl.bat. This will retrieve the version of
175 the sources matched to the current commit from the OpenSSL branch
176 in our source repository at
177 https://github.com/python/cpython-source-deps.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500178
Steve Dowerbab21fa2017-09-07 20:10:29 -0700179 To use an alternative build of OpenSSL completely, you should replace
180 the files in the externals/openssl-bin-<version> folder with your own.
181 As long as this folder exists, its contents will not be downloaded
182 again when building.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500183
Zachary Ware6b6e6872017-06-10 14:58:42 -0500184_sqlite3
185 Wraps SQLite 3.14.2.0, which is itself built by sqlite3.vcxproj
186 Homepage:
187 http://www.sqlite.org/
188_tkinter
Steve Dowerbab21fa2017-09-07 20:10:29 -0700189 Wraps version 8.6.6 of the Tk windowing system, which is downloaded
190 from our binaries repository at
191 https://github.com/python/cpython-bin-deps.
192
Zachary Ware6b6e6872017-06-10 14:58:42 -0500193 Homepage:
194 http://www.tcl.tk/
195
Steve Dowerbab21fa2017-09-07 20:10:29 -0700196 Building Tcl and Tk can be performed by running
197 PCbuild\prepare_tcltk.bat. This will retrieve the version of the
198 sources matched to the current commit from the Tcl and Tk branches
199 in our source repository at
200 https://github.com/python/cpython-source-deps.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500201
Steve Dowerbab21fa2017-09-07 20:10:29 -0700202 The two projects install their respective components in a
Zachary Ware6b6e6872017-06-10 14:58:42 -0500203 directory alongside the source directories called "tcltk" on
204 Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs
205 into the current output directory, which should ensure that Tkinter
206 is able to load Tcl/Tk without having to change your PATH.
207
Zachary Ware6b6e6872017-06-10 14:58:42 -0500208
209Getting External Sources
210------------------------
211
212The last category of sub-projects listed above wrap external projects
213Python doesn't control, and as such a little more work is required in
214order to download the relevant source files for each project before they
215can be built. However, a simple script is provided to make this as
216painless as possible, called "get_externals.bat" and located in this
217directory. This script extracts all the external sub-projects from
Zachary Ware51599e22017-06-15 22:08:51 -0500218 https://github.com/python/cpython-source-deps
219and
220 https://github.com/python/cpython-bin-deps
221via a Python script called "get_external.py", located in this directory.
222If Python 3.6 or later is not available via the "py.exe" launcher, the
223path or command to use for Python can be provided in the PYTHON_FOR_BUILD
224environment variable, or get_externals.bat will download the latest
225version of NuGet and use it to download the latest "pythonx86" package
226for use with get_external.py. Everything downloaded by these scripts is
227stored in ..\externals (relative to this directory).
Zachary Ware6b6e6872017-06-10 14:58:42 -0500228
229It is also possible to download sources from each project's homepage,
230though you may have to change folder names or pass the names to MSBuild
231as the values of certain properties in order for the build solution to
232find them. This is an advanced topic and not necessarily fully
233supported.
234
Steve Dowerbab21fa2017-09-07 20:10:29 -0700235The get_externals.bat script is called automatically by build.bat
236unless you pass the '-E' option.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500237
238
239Profile Guided Optimization
240---------------------------
241
242The solution has two configurations for PGO. The PGInstrument
243configuration must be built first. The PGInstrument binaries are linked
244against a profiling library and contain extra debug information. The
245PGUpdate configuration takes the profiling data and generates optimized
246binaries.
247
248The build_pgo.bat script automates the creation of optimized binaries.
249It creates the PGI files, runs the unit test suite or PyBench with the
250PGI python, and finally creates the optimized files.
251
252See
253 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.140).aspx
254for more on this topic.
255
256
257Static library
258--------------
259
260The solution has no configuration for static libraries. However it is
261easy to build a static library instead of a DLL. You simply have to set
262the "Configuration Type" to "Static Library (.lib)" and alter the
263preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
264also have to change the "Runtime Library" from "Multi-threaded DLL
265(/MD)" to "Multi-threaded (/MT)".
266
267
268Visual Studio properties
269------------------------
270
271The PCbuild solution makes use of Visual Studio property files (*.props)
272to simplify each project. The properties can be viewed in the Property
273Manager (View -> Other Windows -> Property Manager) but should be
274carefully modified by hand.
275
276The property files used are:
277 * python (versions, directories and build names)
278 * pyproject (base settings for all projects)
Steve Dowerbab21fa2017-09-07 20:10:29 -0700279 * openssl (used by projects dependent upon OpenSSL)
Zachary Ware6b6e6872017-06-10 14:58:42 -0500280 * tcltk (used by _tkinter, tcl, tk and tix projects)
281
282The pyproject property file defines all of the build settings for each
283project, with some projects overriding certain specific values. The GUI
284doesn't always reflect the correct settings and may confuse the user
285with false information, especially for settings that automatically adapt
286for diffirent configurations.