• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

appendpath/25-Apr-2025-6857

bundle/25-Apr-2025-4,8513,823

core/25-Apr-2025-139125

dev/25-Apr-2025-120107

doc/25-Apr-2025-8980

exe/25-Apr-2025-265238

launcher/25-Apr-2025-236201

lib/25-Apr-2025-260229

path/25-Apr-2025-6757

pip/25-Apr-2025-6653

tcltk/25-Apr-2025-291263

test/25-Apr-2025-164142

tools/25-Apr-2025-8477

ucrt/25-Apr-2025-5045

README.txtD25-Apr-202522 KiB529395

build.batD25-Apr-20253.2 KiB9785

buildrelease.batD25-Apr-202510 KiB262229

common.wxsD25-Apr-20254.9 KiB139115

common_en-US.wxl_templateD25-Apr-20251.4 KiB1918

csv_to_wxs.pyD25-Apr-20254.9 KiB128103

generate_md5.pyD25-Apr-2025679 2820

get_externals.batD25-Apr-20252.7 KiB9275

make_appx.ps1D25-Apr-20252.2 KiB7245

make_cat.ps1D25-Apr-20251.4 KiB4623

make_zip.projD25-Apr-20251.9 KiB4134

msi.propsD25-Apr-20259.2 KiB190161

msi.targetsD25-Apr-20255.8 KiB9682

purge.pyD25-Apr-20252.1 KiB8571

sdktools.psm1D25-Apr-20251.5 KiB4941

sign_build.ps1D25-Apr-20251 KiB3416

testrelease.batD25-Apr-20254.1 KiB11897

uploadrelease.batD25-Apr-20255 KiB11098

uploadrelease.projD25-Apr-20256.7 KiB11499

uploadrelease.ps1D25-Apr-20255.4 KiB172117

wix.propsD25-Apr-2025974 1211

README.txt

1Quick Build Info
2================
3
4For testing, the installer should be built with the Tools/msi/build.bat
5script:
6
7    build.bat [-x86] [-x64] [-ARM64] [--doc]
8
9For an official release, the installer should be built with the
10Tools/msi/buildrelease.bat script and environment variables:
11
12    set PYTHON=<path to Python 3.8 or later>
13    set SPHINXBUILD=<path to sphinx-build.exe>
14    set PATH=<path to Git (git.exe)>;%PATH%
15
16    buildrelease.bat [-x86] [-x64] [-ARM64] [-D] [-B]
17        [-o <output directory>] [-c <certificate name>]
18
19See the Building the Installer section for more information.
20
21Overview
22========
23
24Python is distributed on Windows as an installer that will configure the
25user's system. This allows users to have a functioning copy of Python
26without having to build it themselves.
27
28The main tasks of the installer are:
29
30* copy required files into the expected layout
31* configure system settings so the installation can be located by
32  other programs
33* add entry points for modifying, repairing and uninstalling Python
34* make it easy to launch Python, its documentation, and IDLE
35
36Each of these is discussed in a later section of this document.
37
38Structure of the Installer
39==========================
40
41The installer is structured as a 'layout', which consists of a number of
42CAB and MSI files and a single EXE.
43
44The EXE is the main entry point into the installer. It contains the UI
45and command-line logic, as well as the ability to locate and optionally
46download other parts of the layout.
47
48Each MSI contains the logic required to install a component or feature
49of Python. These MSIs should not be launched directly by users. MSIs can
50be embedded into the EXE or automatically downloaded as needed.
51
52Each CAB contains the files making up a Python installation. CABs are
53embedded into their associated MSI and are never seen by users.
54
55MSIs are only required when the related feature or component is being
56installed. When components are not selected for installation, the
57associated MSI is not downloaded. This allows the installer to offer
58options to install debugging symbols and binaries without increasing
59the initial download size by separating them into their own MSIs.
60
61Building the Installer
62======================
63
64Before building the installer, download extra build dependencies using
65Tools\msi\get_externals.bat. (Note that this is in addition to the
66similarly named file in PCbuild.)
67
68One of the dependencies used in builds is WiX, a toolset that lets developers
69create installers for Windows Installer, the Windows installation engine. WiX
70has a dependency on the Microsoft .NET Framework Version 3.5 (which may not be
71configured on recent versions of Windows, such as Windows 10). If you are
72building on a recent Windows version, use the Control Panel (Programs | Programs
73and Features | Turn Windows Features on or off) and ensure that the entry
74".NET Framework 3.5 (includes .NET 2.0 and 3.0)" is enabled.
75
76For testing, the installer should be built with the Tools/msi/build.bat
77script:
78
79    build.bat [-x86] [-x64] [-ARM64] [--doc] [--test-marker] [--pack]
80
81This script will build the required configurations of Python and
82generate an installer layout in PCbuild/(win32|amd64)/en-us.
83
84Specify -x86, -x64 and/or -ARM64 to build for each platform. If none are
85specified, both x64 and x86 will be built. Currently, both the debug and
86release versions of Python are required for the installer.
87
88Specify --doc to include the documentation files. Ensure %PYTHON% and
89%SPHINXBUILD% are set when passing this option.
90
91Specify --test-marker to build an installer that works side-by-side with
92an official Python release. All registry keys and install locations will
93include an extra marker to avoid overwriting files. This marker is
94currently an 'x' prefix, but may change at any time.
95
96Specify --pack to build an installer that does not require all MSIs to
97be available alongside. This takes longer, but is easier to share.
98
99
100For an official release, the installer should be built with the
101Tools/msi/buildrelease.bat script:
102
103    set PYTHON=<path to Python 2.7 or 3.4>
104    set SPHINXBUILD=<path to sphinx-build.exe>
105    set PATH=<path to Git (git.exe)>;%PATH%
106
107    buildrelease.bat [-x86] [-x64] [-ARM64] [-D] [-B]
108        [-o <output directory>] [-c <certificate name>]
109
110Specify -x86, -x64 and/or -ARM64 to build for each platform. If none are
111specified, both x64 and x86 will be built. Currently, both the debug and
112release versions of Python are required for the installer.
113
114Specify -D to skip rebuilding the documentation. The documentation is
115required for a release and the build will fail if it is not available.
116Ensure %PYTHON% and %SPHINXBUILD% are set if you omit this option.
117
118Specify -B to skip rebuilding Python. This is useful to only rebuild the
119installer layout after a previous call to buildrelease.bat.
120
121Specify -o to set an output directory. The installer layouts will be
122copied to platform-specific subdirectories of this path.
123
124Specify -c to choose a code-signing certificate to be used for all the
125signable binaries in Python as well as each file making up the
126installer. Official releases of Python must be signed.
127
128
129If WiX is not found on your system, it will be automatically downloaded
130and extracted to the externals/ directory.
131
132To manually build layouts of the installer, build one of the projects in
133the bundle folder.
134
135    msbuild bundle\snapshot.wixproj
136    msbuild bundle\releaseweb.wixproj
137    msbuild bundle\releaselocal.wixproj
138    msbuild bundle\full.wixproj
139
140snapshot.wixproj produces a test installer versioned based on the date.
141
142releaseweb.wixproj produces a release installer that does not embed any
143of the layout.
144
145releaselocal.wixproj produces a release installer that embeds the files
146required for a default installation.
147
148full.wixproj produces a test installer that embeds the entire layout.
149
150The following properties may be passed when building these projects.
151
152  /p:BuildForRelease=(true|false)
153    When true, adds extra verification to ensure a complete installer is
154    produced. Defaults to false.
155
156  /p:ReleaseUri=(any URI)
157    Used to generate unique IDs for the installers to allow side-by-side
158    installation. Forks of Python can use the same installer infrastructure
159    by providing a unique URI for this property. It does not need to be an
160    active internet address. Defaults to $(ComputerName).
161
162    Official releases use https://www.python.org/(architecture name)
163
164  /p:DownloadUrlBase=(any URI)
165    Specifies the base of a URL where missing parts of the installer layout
166    can be downloaded from. The build version and architecture will be
167    appended to create the full address. If omitted, missing components will
168    not be automatically downloaded.
169
170  /p:DownloadUrl=(any URI)
171    Specifies the full URL where missing parts of the installer layout can
172    be downloaded from. Should normally include '{2}', which will be
173    substituted for the filename. If omitted, missing components will not be
174    automatically downloaded. If specified, this value overrides
175    DownloadUrlBase.
176
177  /p:SigningCertificate=(certificate name)
178    Specifies the certificate to sign the installer layout with. If omitted,
179    the layout will not be signed.
180
181  /p:RebuildAll=(true|false)
182    When true, rebuilds all of the MSIs making up the layout. Defaults to
183    true.
184
185Uploading the Installer
186=======================
187
188For official releases, the uploadrelease.bat script should be used.
189
190You will require PuTTY so that plink.exe and pscp.exe can be used, and your
191SSH key can be activated in pageant.exe. PuTTY should be either on your path
192or in %ProgramFiles(x86)%\PuTTY.
193
194To include signatures for each uploaded file, you will need gpg2.exe on your
195path or have run get_externals.bat. You may also need to "gpg2.exe --import"
196your key before running the upload script.
197
198    uploadrelease.bat --host <host> --user <username> [--dry-run] [--no-gpg]
199
200The host is the URL to the server. This can be provided by the Release
201Manager. You should be able to SSH to this address.
202
203The username is your own username, which you have permission to SSH into
204the server containing downloads.
205
206Use --dry-run to display the generated upload commands without executing
207them. Signatures for each file will be generated but not uploaded unless
208--no-gpg is also passed.
209
210Use --no-gpg to suppress signature generation and upload.
211
212The default target directory (which appears in uploadrelease.proj) is
213correct for official Python releases, but may be overridden with
214--target <path> for other purposes. This path should generally not include
215any version specifier, as that will be added automatically.
216
217Modifying the Installer
218=======================
219
220The code for the installer is divided into three main groups: packages,
221the bundle and the bootstrap application.
222
223Packages
224--------
225
226Packages appear as subdirectories of Tools/msi (other than the bundle/
227directory). The project file is a .wixproj and the build output is a
228single MSI. Packages are built with the WiX Toolset. Some project files
229share source files and use preprocessor directives to enable particular
230features. These are typically used to keep the sources close when the
231files are related, but produce multiple independent packages.
232
233A package is the smallest element that may be independently installed or
234uninstalled (as used in this installer). For example, the test suite has
235its own package, as users can choose to add or remove it after the
236initial installation.
237
238All the files installed by a single package should be related, though
239some packages may not install any files. For example, the pip package
240executes the ensurepip package, but does not add or remove any of its
241own files. (It is represented as a package because of its
242installed/uninstalled nature, as opposed to the "precompile standard
243library" option, for example.) Dependencies between packages are handled
244by the bundle, but packages should detect when dependencies are missing
245and raise an error.
246
247Packages that include a lot of files may use an InstallFiles element in
248the .wixproj file to generate sources. See lib/lib.wixproj for an
249example, and msi.targets and csv_to_wxs.py for the implementation. This
250element is also responsible for generating the code for cleaning up and
251removing __pycache__ folders in any directory containing .py files.
252
253All packages are built with the Tools/msi/common.wxs file, and so any
254directory or property in this file may be referenced. Of particular
255interest:
256
257  REGISTRYKEY (property)
258    The registry key for the current installation.
259
260  InstallDirectory (directory)
261    The root install directory for the current installation. Subdirectories
262    are also specified in this file (DLLs, Lib, etc.)
263
264  MenuDir (directory)
265    The Start Menu folder for the current installation.
266
267  UpgradeTable (property)
268    Every package should reference this property to include upgrade
269    information.
270
271  OptionalFeature (Component)
272    Packages that may be enabled or disabled should reference this component
273    and have an OPTIONAL_FEATURES entry in the bootstrap application to
274    properly handle Modify and Upgrade.
275
276The .wxl_template file is specially handled by the build system for this
277project to perform {{substitutions}} as defined in msi.targets. They
278should be included in projects as <WxlTemplate> items, where .wxl files
279are normally included as <EmbeddedResource> items.
280
281Bundle
282------
283
284The bundle is compiled to the main EXE entry point that for most users
285will represent the Python installer. It is built from Tools/msi/bundle
286with packages references in Tools/msi/bundle/packagegroups.
287
288Build logic for the bundle is in bundle.targets, but should be invoked
289through one of the .wixproj files as described in Building the
290Installer.
291
292The UI is separated between Default.thm (UI layout), Default.wxl
293(strings), bundle.wxs (properties) and the bootstrap application.
294Bundle.wxs also contains the chain, which is the list of packages to
295install and the order they should be installed in. These refer to named
296package groups in bundle/packagegroups.
297
298Each package group specifies one or more packages to install. Most
299packages require two separate entries to support both per-user and
300all-users installations. Because these reuse the same package, it does
301not increase the overall size of the package.
302
303Package groups refer to payload groups, which allow better control over
304embedding and downloading files than the default settings. Whether files
305are embedded and where they are downloaded from depends on settings
306created by the project files.
307
308Package references can include install conditions that determine when to
309install the package. When a package is a dependency for others, the
310condition should be crafted to ensure it is installed.
311
312MSI packages are installed or uninstalled based on their current state
313and the install condition. This makes them most suitable for features
314that are clearly present or absent from the user's machine.
315
316EXE packages are executed based on a customisable condition that can be
317omitted. This makes them suitable for pre- or post-install tasks that
318need to run regardless of whether features have been added or removed.
319
320Bootstrap Application
321---------------------
322
323The bootstrap application is a C++ application that controls the UI and
324installation. While it does not directly compile into the main EXE of
325the installer, it forms the main active component. Most of the
326installation functionality is provided by WiX, and so the bootstrap
327application is predominantly responsible for the code behind the UI that
328is defined in the Default.thm file. The bootstrap application code is in
329bundle/bootstrap and is built automatically when building the bundle.
330
331Installation Layout
332===================
333
334There are two installation layouts for Python on Windows, with the only
335differences being supporting files. A layout is selected implicitly
336based on whether the install is for all users of the machine or just for
337the user performing the installation.
338
339The default installation location when installing for all users is
340"%ProgramFiles%\Python3X" for the 64-bit interpreter and
341"%ProgramFiles(x86)%\Python3X-32" for the 32-bit interpreter. (Note that
342the latter path is equivalent to "%ProgramFiles%\Python3X-32" when
343running a 32-bit version of Windows.) This location requires
344administrative privileges to install or later modify the installation.
345
346The default installation location when installing for the current user
347is "%LocalAppData%\Programs\Python\Python3X" for the 64-bit interpreter
348and "%LocalAppData%\Programs\Python\Python3X-32" for the 32-bit
349interpreter. Only the current user can access this location. This
350provides a suitable level of protection against malicious modification
351of Python's files.
352
353(Default installation locations are set in Tools\msi\bundle\bundle.wxs.)
354
355Within this install directory is the following approximate layout:
356
357.\python[w].exe The core executable files
358.\python3x.dll  The core interpreter
359.\python3.dll   The stable ABI reference
360.\DLLs          Stdlib extensions (*.pyd) and dependencies
361.\Doc           Documentation (*.html)
362.\include       Development headers (*.h)
363.\Lib           Standard library
364.\Lib\test      Test suite
365.\libs          Development libraries (*.lib)
366.\Scripts       Launcher scripts (*.exe, *.py)
367.\tcl           Tcl dependencies (*.dll, *.tcl and others)
368.\Tools         Tool scripts (*.py)
369
370When installed for all users, the following files are installed to
371"%SystemRoot%" (typically "C:\Windows") to ensure they are always
372available on PATH. (See Launching Python below.) For the current user,
373they are installed in "%LocalAppData%\Programs\Python\PyLauncher".
374
375.\py[w].exe         PEP 397 launcher
376
377
378System Settings
379===============
380
381On installation, registry keys are created so that other applications
382can locate and identify installations of Python. The locations of these
383keys vary based on the install type.
384
385For 64-bit interpreters installed for all users, the root key is:
386    HKEY_LOCAL_MACHINE\Software\Python\PythonCore\3.X
387
388For 32-bit interpreters installed for all users on a 64-bit operating
389system, the root key is:
390    HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\PythonCore\3.X-32
391
392For 32-bit interpreters installed for all users on a 32-bit operating
393system, the root key is:
394    HKEY_LOCAL_MACHINE\Software\Python\PythonCore\3.X-32
395
396For 64-bit interpreters installed for the current user:
397    HKEY_CURRENT_USER\Software\Python\PythonCore\3.X
398
399For 32-bit interpreters installed for the current user:
400    HKEY_CURRENT_USER\Software\Python\PythonCore\3.X-32
401
402When the core Python executables are installed, a key "InstallPath" is
403created within the root key with its default value set to the
404executable's install directory. A value named "ExecutablePath" is added
405with the full path to the main Python interpreter, and a key
406"InstallGroup" is created with its default value set to the product
407name "Python 3.X".
408
409When the Python standard library is installed, a key "PythonPath" is
410created within the root key with its default value set to the full path
411to the Lib folder followed by the path to the DLLs folder, separated by
412a semicolon.
413
414When the documentation is installed, a key "Help" is created within the
415root key, with a subkey "Main Python Documentation" with its default
416value set to the full path to the main index.html file.
417
418
419The py.exe launcher is installed as part of a regular Python install,
420but using a separate mechanism that allows it to more easily span
421versions of Python. As a result, it has different root keys for its
422registry entries:
423
424When installed for all users on a 64-bit operating system, the
425launcher's root key is:
426    HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python\Launcher
427
428When installed for all users on a 32-bit operating system, the
429launcher's root key is:
430    HKEY_LOCAL_MACHINE\Software\Python\Launcher
431
432When installed for the current user:
433    HKEY_CURRENT_USER\Software\Python\Launcher
434
435When the launcher is installed, a key "InstallPath" is created within
436its root key with its default value set to the launcher's install
437directory. File associations are also created for .py, .pyw, .pyc and
438.pyo files.
439
440Launching Python
441================
442
443When a feature offering user entry points in the Start Menu is
444installed, a folder "Python 3.X" is created. Every shortcut should be
445created within this folder, and each shortcut should include the version
446and platform to allow users to identify the shortcut in a search results
447page.
448
449The core Python executables creates a shortcut "Python 3.X (32-bit)" or
450"Python 3.X (64-bit)" depending on the interpreter.
451
452The documentation creates a shortcut "Python 3.X 32-bit Manuals" or
453"Python 3.X 64-bit Manuals". The documentation is identical for all
454platforms, but the shortcuts need to be separate to avoid uninstallation
455conflicts.
456
457Installing IDLE creates a shortcut "IDLE (Python 3.X 32-bit)" or "IDLE
458(Python 3.X 64-bit)" depending on the interpreter.
459
460
461For users who often launch Python from a Command Prompt, an option is
462provided to add the directory containing python.exe to the user or
463system PATH variable. If the option is selected, the install directory
464and the Scripts directory will be added at the start of the system PATH
465for an all users install and the user PATH for a per-user install.
466
467When the user only has one version of Python installed, this will behave
468as expected. However, because Windows searches the system PATH before
469the user PATH, users cannot override a system-wide installation of
470Python on their PATH. Further, because the installer can only prepend to
471the path, later installations of Python will take precedence over
472earlier installations, regardless of interpreter version.
473
474Because it is not possible to automatically create a sensible PATH
475configuration, users are recommended to use the py.exe launcher and
476manually modify their PATH variable to add Scripts directories in their
477preferred order. System-wide installations of Python should consider not
478modifying PATH, or using an alternative technology to modify their
479users' PATH variables.
480
481
482The py.exe launcher is recommended because it uses a consistent and
483sensible search order for Python installations. User installations are
484preferred over system-wide installs, and later versions are preferred
485regardless of installation order (with the exception that py.exe
486currently prefers 2.x versions over 3.x versions without the -3 command
487line argument).
488
489For both 32-bit and 64-bit interpreters, the 32-bit version of the
490launcher is installed. This ensures that the search order is always
491consistent (as the 64-bit launcher is subtly different from the 32-bit
492launcher) and also avoids the need to install it multiple times. Future
493versions of Python will upgrade the launcher in-place, using Windows
494Installer's upgrade functionality to avoid conflicts with earlier
495installed versions.
496
497When installed, file associations are created for .py, .pyc and .pyo
498files to launch with py.exe and .pyw files to launch with pyw.exe. This
499makes Python files respect shebang lines by default and also avoids
500conflicts between multiple Python installations.
501
502
503Repair, Modify and Uninstall
504============================
505
506After installation, Python may be modified, repaired or uninstalled by
507running the original EXE again or via the Programs and Features applet
508(formerly known as Add or Remove Programs).
509
510Modifications allow features to be added or removed. The install
511directory and kind (all users/single user) cannot be modified. Because
512Windows Installer caches installation packages, removing features will
513not require internet access unless the package cache has been corrupted
514or deleted. Adding features that were not previously installed and are
515not embedded or otherwise available will require internet access.
516
517Repairing will rerun the installation for all currently installed
518features, restoring files and registry keys that have been modified or
519removed. This operation generally will not redownload any files unless
520the cached packages have been corrupted or deleted.
521
522Removing Python will clean up all the files and registry keys that were
523created by the installer, as well as __pycache__ folders that are
524explicitly handled by the installer. Python packages installed later
525using a tool like pip will not be removed. Some components may be
526installed by other installers and these will not be removed if another
527product has a dependency on them.
528
529