blob: 4335c9f71d0d260b93619b267986443cc2f06241 [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
native-apifd0fa672017-11-17 02:56:27 +030028To build an installer package, refer to the README in the Tools/msi folder.
29
Zachary Ware6b6e6872017-06-10 14:58:42 -050030The solution currently supports two platforms. The Win32 platform is
31used to build standard x86-compatible 32-bit binaries, output into the
32win32 sub-directory. The x64 platform is used for building 64-bit AMD64
33(aka x86_64 or EM64T) binaries, output into the amd64 sub-directory.
34The Itanium (IA-64) platform is no longer supported.
35
36Four configuration options are supported by the solution:
37Debug
38 Used to build Python with extra debugging capabilities, equivalent
39 to using ./configure --with-pydebug on UNIX. All binaries built
40 using this configuration have "_d" added to their name:
Pablo Galindod4fe0982020-05-19 03:33:01 +010041 python310_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
Zachary Ware6b6e6872017-06-10 14:58:42 -050042 build and rt (run test) batch files in this directory accept a -d
43 option for debug builds. If you are building Python to help with
44 development of CPython, you will most likely use this configuration.
45PGInstrument, PGUpdate
46 Used to build Python in Release configuration using PGO, which
47 requires Premium Edition of Visual Studio. See the "Profile
48 Guided Optimization" section below for more information. Build
49 output from each of these configurations lands in its own
50 sub-directory of this directory. The official Python releases may
51 be built using these configurations.
52Release
53 Used to build Python as it is meant to be used in production
54 settings, though without PGO.
55
56
57Building Python using the build.bat script
58----------------------------------------------
59
60In this directory you can find build.bat, a script designed to make
61building Python on Windows simpler. This script will use the env.bat
Steve Dowerbab21fa2017-09-07 20:10:29 -070062script to detect either Visual Studio 2017 or 2015, either of
63which may be used to build Python. Currently Visual Studio 2017 is
Zachary Ware6b6e6872017-06-10 14:58:42 -050064officially supported.
65
66By default, build.bat will build Python in Release configuration for
67the 32-bit Win32 platform. It accepts several arguments to change
68this behavior, try `build.bat -h` to learn more.
69
70
71C Runtime
72---------
73
Steve Dowerbab21fa2017-09-07 20:10:29 -070074Visual Studio 2017 uses version 14.0 of the C runtime (vcruntime140).
75The executables no longer use the "Side by Side" assemblies used in
76previous versions of the compiler. This simplifies distribution of
77applications.
Zachary Ware6b6e6872017-06-10 14:58:42 -050078
Steve Dowerbab21fa2017-09-07 20:10:29 -070079The run time libraries are available under the redist folder of your
Zachary Ware6b6e6872017-06-10 14:58:42 -050080Visual Studio distribution. For more info, see the Readme in the
Steve Dowerbab21fa2017-09-07 20:10:29 -070081redist folder.
Zachary Ware6b6e6872017-06-10 14:58:42 -050082
83
84Sub-Projects
85------------
86
87The CPython project is split up into several smaller sub-projects which
88are managed by the pcbuild.sln solution file. Each sub-project is
89represented by a .vcxproj and a .vcxproj.filters file starting with the
90name of the sub-project. These sub-projects fall into a few general
91categories:
92
93The following sub-projects represent the bare minimum required to build
94a functioning CPython interpreter. If nothing else builds but these,
95you'll have a very limited but usable python.exe:
96pythoncore
97 .dll and .lib
98python
99 .exe
100
101These sub-projects provide extra executables that are useful for running
102CPython in different ways:
103pythonw
104 pythonw.exe, a variant of python.exe that doesn't open a Command
105 Prompt window
106pylauncher
107 py.exe, the Python Launcher for Windows, see
108 http://docs.python.org/3/using/windows.html#launcher
109pywlauncher
110 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
111 window
112_testembed
113 _testembed.exe, a small program that embeds Python for testing
114 purposes, used by test_capi.py
115
116These are miscellaneous sub-projects that don't really fit the other
117categories:
118_freeze_importlib
119 _freeze_importlib.exe, used to regenerate Python\importlib.h after
120 changes have been made to Lib\importlib\_bootstrap.py
Steve Dowerbab21fa2017-09-07 20:10:29 -0700121pyshellext
122 pyshellext.dll, the shell extension deployed with the launcher
Zachary Ware6b6e6872017-06-10 14:58:42 -0500123python3dll
124 python3.dll, the PEP 384 Stable ABI dll
125xxlimited
126 builds an example module that makes use of the PEP 384 Stable ABI,
127 see Modules\xxlimited.c
Petr Viktorinc168b502020-12-08 17:36:53 +0100128xxlimited_35
129 ditto for testing the Python 3.5 stable ABI, see
130 Modules\xxlimited_35.c
Zachary Ware6b6e6872017-06-10 14:58:42 -0500131
132The following sub-projects are for individual modules of the standard
133library which are implemented in C; each one builds a DLL (renamed to
134.pyd) of the same name as the project:
Steve Dowerbab21fa2017-09-07 20:10:29 -0700135_asyncio
Zachary Ware6b6e6872017-06-10 14:58:42 -0500136_ctypes
137_ctypes_test
Paul Ganssle62972d92020-05-16 04:20:06 -0400138_zoneinfo
Zachary Ware6b6e6872017-06-10 14:58:42 -0500139_decimal
140_elementtree
141_hashlib
142_msi
143_multiprocessing
144_overlapped
145_socket
Zachary Ware6b6e6872017-06-10 14:58:42 -0500146_testbuffer
Steve Dowerbab21fa2017-09-07 20:10:29 -0700147_testcapi
148_testconsole
Zachary Ware6b6e6872017-06-10 14:58:42 -0500149_testimportmultiple
Steve Dowerbab21fa2017-09-07 20:10:29 -0700150_testmultiphase
151_tkinter
Zachary Ware6b6e6872017-06-10 14:58:42 -0500152pyexpat
153select
154unicodedata
155winsound
156
157The following Python-controlled sub-projects wrap external projects.
158Note that these external libraries are not necessary for a working
159interpreter, but they do implement several major features. See the
160"Getting External Sources" section below for additional information
161about getting the source for building these libraries. The sub-projects
162are:
163_bz2
164 Python wrapper for version 1.0.6 of the libbzip2 compression library
165 Homepage:
166 http://www.bzip.org/
167_lzma
Zachary Ware51599e22017-06-15 22:08:51 -0500168 Python wrapper for version 5.2.2 of the liblzma compression library
Zachary Ware6b6e6872017-06-10 14:58:42 -0500169 Homepage:
170 http://tukaani.org/xz/
171_ssl
Steve Dowera268edd2019-06-17 11:36:08 -0700172 Python wrapper for version 1.1.1c of the OpenSSL secure sockets
Steve Dowerbab21fa2017-09-07 20:10:29 -0700173 library, which is downloaded from our binaries repository at
174 https://github.com/python/cpython-bin-deps.
175
Zachary Ware6b6e6872017-06-10 14:58:42 -0500176 Homepage:
177 http://www.openssl.org/
178
Steve Dowerbab21fa2017-09-07 20:10:29 -0700179 Building OpenSSL requires Perl on your path, and can be performed by
180 running PCbuild\prepare_ssl.bat. This will retrieve the version of
181 the sources matched to the current commit from the OpenSSL branch
182 in our source repository at
183 https://github.com/python/cpython-source-deps.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500184
Steve Dowerbab21fa2017-09-07 20:10:29 -0700185 To use an alternative build of OpenSSL completely, you should replace
186 the files in the externals/openssl-bin-<version> folder with your own.
187 As long as this folder exists, its contents will not be downloaded
188 again when building.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500189
Zachary Ware6b6e6872017-06-10 14:58:42 -0500190_sqlite3
Erlend Egeberg Aaslandbfe6e032020-10-08 20:40:27 +0200191 Wraps SQLite 3.33.0, which is itself built by sqlite3.vcxproj
Zachary Ware6b6e6872017-06-10 14:58:42 -0500192 Homepage:
193 http://www.sqlite.org/
194_tkinter
Steve Dowerbab21fa2017-09-07 20:10:29 -0700195 Wraps version 8.6.6 of the Tk windowing system, which is downloaded
196 from our binaries repository at
197 https://github.com/python/cpython-bin-deps.
198
Zachary Ware6b6e6872017-06-10 14:58:42 -0500199 Homepage:
200 http://www.tcl.tk/
201
Steve Dowerbab21fa2017-09-07 20:10:29 -0700202 Building Tcl and Tk can be performed by running
203 PCbuild\prepare_tcltk.bat. This will retrieve the version of the
204 sources matched to the current commit from the Tcl and Tk branches
205 in our source repository at
206 https://github.com/python/cpython-source-deps.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500207
Steve Dowerbab21fa2017-09-07 20:10:29 -0700208 The two projects install their respective components in a
Zachary Ware6b6e6872017-06-10 14:58:42 -0500209 directory alongside the source directories called "tcltk" on
210 Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs
211 into the current output directory, which should ensure that Tkinter
212 is able to load Tcl/Tk without having to change your PATH.
213
Zachary Ware6b6e6872017-06-10 14:58:42 -0500214
215Getting External Sources
216------------------------
217
218The last category of sub-projects listed above wrap external projects
219Python doesn't control, and as such a little more work is required in
220order to download the relevant source files for each project before they
221can be built. However, a simple script is provided to make this as
222painless as possible, called "get_externals.bat" and located in this
223directory. This script extracts all the external sub-projects from
Zachary Ware51599e22017-06-15 22:08:51 -0500224 https://github.com/python/cpython-source-deps
225and
226 https://github.com/python/cpython-bin-deps
227via a Python script called "get_external.py", located in this directory.
228If Python 3.6 or later is not available via the "py.exe" launcher, the
229path or command to use for Python can be provided in the PYTHON_FOR_BUILD
230environment variable, or get_externals.bat will download the latest
231version of NuGet and use it to download the latest "pythonx86" package
232for use with get_external.py. Everything downloaded by these scripts is
233stored in ..\externals (relative to this directory).
Zachary Ware6b6e6872017-06-10 14:58:42 -0500234
235It is also possible to download sources from each project's homepage,
236though you may have to change folder names or pass the names to MSBuild
237as the values of certain properties in order for the build solution to
238find them. This is an advanced topic and not necessarily fully
239supported.
240
Steve Dowerbab21fa2017-09-07 20:10:29 -0700241The get_externals.bat script is called automatically by build.bat
242unless you pass the '-E' option.
Zachary Ware6b6e6872017-06-10 14:58:42 -0500243
244
245Profile Guided Optimization
246---------------------------
247
248The solution has two configurations for PGO. The PGInstrument
249configuration must be built first. The PGInstrument binaries are linked
250against a profiling library and contain extra debug information. The
251PGUpdate configuration takes the profiling data and generates optimized
252binaries.
253
254The build_pgo.bat script automates the creation of optimized binaries.
255It creates the PGI files, runs the unit test suite or PyBench with the
256PGI python, and finally creates the optimized files.
257
258See
259 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.140).aspx
260for more on this topic.
261
262
263Static library
264--------------
265
266The solution has no configuration for static libraries. However it is
267easy to build a static library instead of a DLL. You simply have to set
268the "Configuration Type" to "Static Library (.lib)" and alter the
269preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
270also have to change the "Runtime Library" from "Multi-threaded DLL
271(/MD)" to "Multi-threaded (/MT)".
272
273
274Visual Studio properties
275------------------------
276
277The PCbuild solution makes use of Visual Studio property files (*.props)
278to simplify each project. The properties can be viewed in the Property
279Manager (View -> Other Windows -> Property Manager) but should be
280carefully modified by hand.
281
282The property files used are:
283 * python (versions, directories and build names)
284 * pyproject (base settings for all projects)
Steve Dowerbab21fa2017-09-07 20:10:29 -0700285 * openssl (used by projects dependent upon OpenSSL)
Zachary Ware6b6e6872017-06-10 14:58:42 -0500286 * tcltk (used by _tkinter, tcl, tk and tix projects)
287
288The pyproject property file defines all of the build settings for each
289project, with some projects overriding certain specific values. The GUI
290doesn't always reflect the correct settings and may confuse the user
291with false information, especially for settings that automatically adapt
Min ho Kimc4cacc82019-07-31 08:16:13 +1000292for different configurations.