PATH
PATH
LongPathsEnabled
to 1
in the registry keyHKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlFileSystem
.open()
function, the os
module and most otherpath functionality to accept and return paths longer than 260 characters./quiet
option. To skip past the user interaction but still displayprogress and errors, pass the /passive
option. The /uninstall
option may be passed to immediately begin removing Python - no prompt will bedisplayed.name=value
, where the value is usually0
to disable a feature, 1
to enable a feature, or a path. The full listof available options is shown below.Name | Description | Default |
---|---|---|
InstallAllUsers | Perform a system-wide installation. | 0 |
TargetDir | The installation directory | Selected based onInstallAllUsers |
DefaultAllUsersTargetDir | The default installation directoryfor all-user installs | %ProgramFiles%PythonX.Y or %ProgramFiles(x86)%PythonX.Y |
DefaultJustForMeTargetDir | The default install directory forjust-for-me installs | %LocalAppData%ProgramsPythonXY or%LocalAppData%ProgramsPythonXY-32 or%LocalAppData%ProgramsPythonXY-64 |
DefaultCustomTargetDir | The default custom install directorydisplayed in the UI | (empty) |
AssociateFiles | Create file associations if thelauncher is also installed. | 1 |
CompileAll | Compile all .py files to.pyc . | 0 |
PrependPath | Add install and Scripts directoriesto PATH and .PY toPATHEXT | 0 |
Shortcuts | Create shortcuts for the interpreter,documentation and IDLE if installed. | 1 |
Include_doc | Install Python manual | 1 |
Include_debug | Install debug binaries | 0 |
Include_dev | Install developer headers andlibraries | 1 |
Include_exe | Install python.exe andrelated files | 1 |
Include_launcher | Install Python Launcher for Windows. | 1 |
InstallLauncherAllUsers | Installs Python Launcher for Windows for allusers. | 1 |
Include_lib | Install standard library andextension modules | 1 |
Include_pip | Install bundled pip and setuptools | 1 |
Include_symbols | Install debugging symbols (*.pdb) | 0 |
Include_tcltk | Install Tcl/Tk support and IDLE | 1 |
Include_test | Install standard library test suite | 1 |
Include_tools | Install utility scripts | 1 |
LauncherOnly | Only installs the launcher. Thiswill override most other options. | 0 |
SimpleInstall | Disable most install UI | 0 |
SimpleInstallDescription | A custom message to display when thesimplified install UI is used. | (empty) |
unattend.xml
alongside the executable. This file specifies a list of options and values.When a value is provided as an attribute, it will be converted to a number ifpossible. Values provided as element text are always left as strings. Thisexample file sets the same options as the previous example:python-3.9.0.exe
for the actualname of your installer, and to create layouts in their own directories toavoid collisions between files with the same name./quiet
option to hide the progress display.python
. Further, pip and IDLE may be used by typingpip
or idle
. IDLE can also be found in Start.python3.exe
and python3.x.exe
as well aspython.exe
(where 3.x
is the specific version you want to launch,such as 3.9). Open “Manage App Execution Aliases” through Start toselect which version of Python is associated with each command. It isrecommended to make sure that pip
and idle
are consistent withwhichever version of python
is selected.python-mvenv
and activatedand used as normal.PATH
variable, it will be available as python.exe
rather than theone from the Microsoft Store. To access the new installation, usepython3.exe
or python3.x.exe
.py.exe
launcher will detect this Python installation, but will preferinstallations from the traditional installer.TEMP
and the registry.Instead, it will write to a private copy. If your scripts must modify theshared locations, you will need to install the full installer.nuget.exe
command line tool may be downloaded directly fromhttps://aka.ms/nugetclidl
, for example, using curl or PowerShell. With thetool, the latest version of Python for 64-bit or 32-bit machines is installedusing:-Version3.x.y
. The output directorymay be changed from .
, and the package will be installed into asubdirectory. By default, the subdirectory is named the same as the package,and without the -ExcludeVersion
option this name will include the specificversion installed. Inside the subdirectory is a tools
directory thatcontains the Python installation:tools
directory is a buildnative
directory. Thiscontains a MSBuild properties file python.props
that can be used in aC++ project to reference the Python install. Including the settings willautomatically use the headers and import libraries in your build..pyc
files in a ZIP, and python3.dll
, python37.dll
,python.exe
and pythonw.exe
are all provided. Tcl/tk (including alldependants, such as Idle), pip and the Python documentation are not included.ucrtbase.dll
in the system directory.Py_Main
with a hard-coded command line.python.exe
or pythonw.exe
with the requiredcommand-line arguments. In this case, the application will appear to be Pythonand not its actual name, and users may have trouble distinguishing it from otherrunning Python processes or file associations.python.exe
or directly use python3.dll
. For either case,extracting the embedded distribution to a subdirectory of the applicationinstallation is sufficient to provide a loadable Python interpreter.conda
package manager.PATH
by adding the directory containingpython.exe to the start is a common way to ensure the correct versionof Python is launched.PATH
.PYTHONPATH
variable is used by all versions of Python 2 andPython 3, so you should not permanently configure this variable unless itonly includes code that is compatible with all of your installed Pythonversions.PATH
. The location of the Scripts
folder is also added.This allows you to type python to run the interpreter, andpip for the package installer. Thus, you can also execute yourscripts with command line options, see Command line documentation.PATH
using the directions in Excursus: Setting environment variables. Youneed to set your PATH
environment variable to include the directoryof your Python installation, delimited by a semicolon from other entries. Anexample variable could look like this (assuming the first two entries alreadyexisted):locale.getpreferredencoding()
).-Xutf8
command line option, orthe PYTHONUTF8=1
environment variable. See PYTHONUTF8
forenabling UTF-8 mode, and Excursus: Setting environment variables for how to modifyenvironment variables.locale.getpreferredencoding()
returns 'UTF-8'
instead ofthe system encoding. This function is used for the default textencoding in many places, including open()
, Popen
,Path.read_text()
, etc.sys.stdin
, sys.stdout
, and sys.stderr
all use UTF-8 as their text encoding.PYTHONUTF8=1
to the default environment variableswill affect all Python 3.7+ applications on your system.If you have any Python 3.7+ applications which rely on the legacysystem encoding, it is recommended to set the environment variabletemporarily or use the -Xutf8
command line option.PATH
variable, the launcher will correctly select the mostappropriate version of Python. It will prefer per-user installations oversystem-wide ones, and orders by language version rather than using the mostrecently installed version.PATH
. The launcher is compatible with all available versions ofPython, so it does not matter which version is installed. To check that thelauncher is available, execute the following command in Command Prompt:PATH
unless the option was selected on installation.venv
module orthe external virtualenv
tool) active, the launcher will run the virtualenvironment’s interpreter rather than the global one. To run the globalinterpreter, either deactivate the virtual environment, or explicitly specifythe global Python version.hello.py
with thefollowing contents#!python2.6
and you should find the 2.6 versioninformation printed.python
typically refers to Python 2..py
,.pyw
, .pyc
files) when it was installed. This means thatwhen you double-click on one of these files from Windows explorer the launcherwill be used, and therefore you can use the same facilities described above tohave the script specify the version which should be used.#!
, it is known as a“shebang” line. Linux and other Unix like operating systems have nativesupport for such lines and they are commonly used on such systems to indicatehow a script should be executed. This launcher allows the same facilities tobe used with Python scripts on Windows and the examples above demonstrate theiruse./usr/bin/envpython
/usr/bin/python
/usr/local/bin/python
python
/usr
./usr/bin/python2.7-32
will request usage of the32-bit python 2.7./usr/bin/python3-64
)./usr/bin/env
form of shebang line has one further special property.Before looking for installed Python interpreters, this form will search theexecutable PATH
for a Python executable. This corresponds to thebehaviour of the Unix env
program, which performs a PATH
search.-v
optionpy.ini
in the currentuser’s “application data” directory (i.e. the directory returned by calling theWindows function SHGetFolderPath
with CSIDL_LOCAL_APPDATA
) and py.ini
in thesame directory as the launcher. The same .ini files are used for both the‘console’ version of the launcher (i.e. py.exe) and for the ‘windows’ version(i.e. pyw.exe).#!python
has no version qualifier, while#!python3
has a version qualifier which specifies only a major version.PY_PYTHON
can be set to specify the default versionqualifier. If it is not set, the default is “3”. The variable canspecify any value that may be passed on the command line, such as “3”,“3.7”, “3.7-32” or “3.7-64”. (Note that the “-64” option is onlyavailable with the launcher included with Python 3.7 or newer.)PY_PYTHON{major}
(where {major}
is the current major version qualifieras determined above) can be set to specify the full version. If no such optionis found, the launcher will enumerate the installed Python versions and usethe latest minor release found for the major version, which is likely,although not guaranteed, to be the most recently installed version in thatfamily.python
andpython2
will use the latest Python 2.x version installed andthe command python3
will use the latest Python 3.x installed.python3.1
and python2.7
will not consult anyoptions at all as the versions are fully specified.PY_PYTHON=3
, the commands python
and python3
will both usethe latest installed Python 3 version.PY_PYTHON=3.1-32
, the command python
will use the 32-bitimplementation of 3.1 whereas the command python3
will use the latestinstalled Python (PY_PYTHON was not considered at all as a majorversion was specified.)PY_PYTHON=3
and PY_PYTHON3=3.1
, the commandspython
and python3
will both use specifically 3.1[defaults]
and the key name will be the same as theenvironment variables without the leading PY_
prefix (and note thatthe key names in the INI file are case insensitive.) The contents ofan environment variable will override things specified in the INI file.PY_PYTHON=3.1
is equivalent to the INI file containing:PY_PYTHON=3
and PY_PYTHON3=3.1
is equivalent to the INI filecontaining:PYLAUNCH_DEBUG
is set (to any value), thelauncher will print diagnostic information to stderr (i.e. to the console).While this information manages to be simultaneously verbose and terse, itshould allow you to see what versions of Python were located, why aparticular version was chosen and the exact command-line used to execute thetarget Python.C:Python
, the default library would reside inC:PythonLib
and third-party modules should be stored inC:PythonLibsite-packages
.sys.path
, create a ._pth
file with the samename as the DLL (python37._pth
) or the executable (python._pth
) andspecify one line for each path to add to sys.path
. The file based on theDLL name overrides the one based on the executable, which allows paths to berestricted for any program loading the runtime if desired.site
is not imported unless one line in thefile specifies importsite
. Blank paths and lines starting with #
areignored. Each path may be absolute or relative to the location of the file.Import statements other than to site
are not permitted, and arbitrary codecannot be specified..pth
files (without leading underscore) will be processed normallyby the site
module when importsite
has been specified.._pth
file is found, this is how sys.path
is populated onWindows:PYTHONPATH
exists, as described inEnvironment variables, its entries are added next. Note that on Windows,paths in this variable must be separated by semicolons, to distinguish themfrom the colon used in drive identifiers (C:
etc.).SOFTWAREPythonPythonCore{version}PythonPath
under both theHKEY_CURRENT_USER
and HKEY_LOCAL_MACHINE
hives. Subkeys which havesemicolon-delimited path strings as their default value will cause each pathto be added to sys.path
. (Note that all known installers only useHKLM, so HKCU is typically empty.)PYTHONHOME
is set, it is assumed as“Python Home”. Otherwise, the path of the main Python executable is used tolocate a “landmark file” (either Libos.py
or pythonXY.zip
) to deducethe “Python Home”. If a Python home is found, the relevant sub-directoriesadded to sys.path
(Lib
, plat-win
, etc) are based on thatfolder. Otherwise, the core Python path is constructed from the PythonPathstored in the registry.PYTHONPATH
is specified inthe environment, and no registry entries can be found, a default path withrelative entries is used (e.g. .Lib;.plat-win
, etc).pyvenv.cfg
file is found alongside the main executable or in thedirectory one level above the executable, the following variations apply:home
is an absolute path and PYTHONHOME
is not set, thispath is used instead of the path to the main executable when deducing thehome location.python.exe
, or any other .exe in the main Pythondirectory (either an installed version, or directly from the PCbuilddirectory), the core path is deduced, and the core paths in the registry areignored. Other “application paths” in the registry are always read.._pth
file alongside your executable containing thedirectories to include. This will ignore paths listed in the registry andenvironment variables, and also ignore site
unless importsite
islisted.python3.dll
or python37.dll
in your ownexecutable, explicitly call Py_SetPath()
or (at least)Py_SetProgramName()
before Py_Initialize()
.PYTHONPATH
and set PYTHONHOME
before launching python.exe
from your application.python.exe
directly), ensurethat the landmark file (Libos.py
) exists in your install directory.(Note that it will not be detected inside a ZIP file, but a correctly namedZIP file will be detected instead.)._pth
file support and removes applocal
option frompyvenv.cfg
.pythonXX.zip
as a potential landmark when directly adjacentto the executable.Modules
(not PythonPath
)may be imported by importlib.machinery.WindowsRegistryFinder
.This finder is enabled on Windows in 3.6.0 and earlier, but may need tobe explicitly added to sys.meta_path
in the future.distutils
extension (see Extending Distutils) which wraps Python scripts intoexecutable Windows programs (*.exe
files). When you have done this,you can distribute your application without requiring your users to installPython.curses
, is restricted toUnix-like systems, there is a library exclusive to Windows as well: WindowsConsole I/O for Python.CONIO.H
, used to create text user interfaces.PCbuild
directory.PCbuild/readme.txt
for general information on the build process.