Teks sumber — English
Terjemahan — Bahasa Indonesia
When you first install a runtime, you will likely be prompted to add a directory to your :envvar:`PATH`. This is optional, if you prefer to use the ``py`` command, but is offered for those who prefer the full range of aliases (such as |python_x_dot_y_exe_literal|) to be available. The directory will be :file:`%LocalAppData%\\Python\\bin` by default, but may be customized by an administrator. Click Start and search for "Edit environment variables for your account" for the system settings page to add the path.
The recommended command for launching Python is ``python``, which will either launch the version requested by the script being launched, an active virtual environment, or the default installed version, which will be the latest stable release unless configured otherwise. If no version is specifically requested and no runtimes are installed at all, the current latest release will be installed automatically.
For all scenarios involving multiple runtime versions, the recommended command is ``py``. This may be used anywhere in place of ``python`` or the older ``py.exe`` launcher. By default, ``py`` matches the behaviour of ``python``, but also allows command line options to select a specific version as well as subcommands to manage installations. These are detailed below.
Because the ``py`` command may already be taken by the previous version, there is also an unambiguous ``pymanager`` command. Scripted installs that are intending to use Python install manager should consider using ``pymanager``, due to the lower chance of encountering a conflict with existing installs. The only difference between the two commands is when running without any arguments: ``py`` will launch your default interpreter, while ``pymanager`` will display help (``pymanager exec ...`` provides equivalent behaviour to ``py ...``).
To launch your default runtime, run ``python`` or ``py`` with the arguments you want to be passed to the runtime (such as script files or the module to launch):
The default runtime can be overridden with the :envvar:`PYTHON_MANAGER_DEFAULT` environment variable, or a configuration file. See :ref:`pymanager-config` for information about configuration settings.
If no version is specified, but a script file is passed, the script will be inspected for a *shebang line*. This is a special format for the first line in a file that allows overriding the command. See :ref:`pymanager-shebang` for more information. When there is no shebang line, or it cannot be resolved, the script will be launched with the default runtime.
If you are running in an active virtual environment, have not requested a particular version, and there is no shebang line, the default runtime will be that virtual environment. In this scenario, the ``python`` command was likely already overridden and none of these checks occurred. However, this behaviour ensures that the ``py`` command can be used interchangeably.
The ``--one`` or ``-1`` option only displays a single result. If the default runtime is included, it will be the one. Otherwise, the "best" result is shown ("best" is deliberately vaguely defined, but will usually be the most recent version). The result shown by ``py list --one <TAG>`` will match the runtime that would be launched by ``py -V:<TAG>``.
The ``--online`` option is short for passing ``--source=<URL>`` with the default source. Passing either of these options will search the online index for runtimes that can be installed. The result shown by ``py list --online --one <TAG>`` will match the runtime that would be installed by ``py install <TAG>``.
New runtime versions may be added using ``py install``. One or more tags may be specified, and the special tag ``default`` may be used to select the default. Ranges are not supported for installation.
The ``py exec`` command will install the requested runtime if it is not already present. This is controlled by the ``automatic_install`` configuration (:envvar:`PYTHON_MANAGER_AUTOMATIC_INSTALL`), and is enabled by default. If no runtimes are available at all, all launch commands will do an automatic install if the configuration setting allows. This is to ensure a good experience for new users, but should not generally be relied on rather than using the ``py exec`` command or explicit install commands.
This section will describe the defaults, but be aware that modified or overridden installs may resolve settings differently.
``default_tag``
The preferred default version to launch or install. By default, this is interpreted as the most recent non-prerelease version from the CPython team.
``default_platform``
``PYTHON_MANAGER_DEFAULT_PLATFORM``
The preferred default platform to launch or install. This is treated as a suffix to the specified tag, such that |py_v_x_dot_y_literal| would prefer an install for |x_dot_y_64_literal| if it exists (and ``default_platform`` is ``-64``), but will use |x_dot_y_literal| if no tagged install exists.
The location where log files are written. By default, :file:`%TEMP%`.
True to allow automatic installs when using ``py exec`` to launch (or ``py`` when no runtimes are installed yet). Other commands will not automatically install, regardless of this setting. By default, true.
True to allow listing and launching runtimes that were not installed by the Python install manager, or false to exclude them. By default, true.
True to allow shebangs in ``.py`` files to launch applications other than Python runtimes, or false to prevent it. By default, true.
Set the default level of output (0-50). By default, 20. Lower values produce more output. The environment variables are boolean, and may produce additional output during startup that is later suppressed by other configuration.
True to confirm certain actions before taking them (such as uninstall), or false to skip the confirmation. By default, true.
True to generate global commands for installed packages (such as ``pip.exe``). These are defined by the packages themselves. If set to false, only the Python interpreter has global commands created. By default, true. You should run ``py install --refresh`` after changing this setting.
Specify the default format used by the ``py list`` command. By default, ``table``.
The default Python or an active virtual environment will be located and used. As many Python scripts written to work on Unix will already have this line, you should find these scripts can be used by the launcher without modification. If you are writing a new script on Windows which you hope will be useful on Unix, you should use one of the shebang lines starting with ``/usr``.
Since version 26.3 of the Python install manager, custom shebang templates may be added to your configuration file. Add the ``shebang_templates`` object with one member for each template (the string to match) and the command to use when the template is matched. Most commands should be ``py -V:<tag>`` (or ``pyw``) to launch one of your installed runtimes. The ``py -3.<version>`` form is also allowed, as is a plain ``py`` to launch the default. No other arguments are supported.
The behaviour of shebangs in the Python install manager is subtly different from the previous ``py.exe`` launcher, and the old configuration options no longer apply. If you are specifically reliant on the old behaviour or configuration, we recommend installing the `legacy launcher`_. The legacy launcher's ``py`` command will override PyManager's one by default, and you will need to use ``pymanager`` commands for installing and uninstalling.
For situations where an MSIX cannot be installed, such as some older administrative distribution platforms, there is an MSI available from the python.org downloads page. This MSI has no user interface, and can only perform per-machine installs to its default location in Program Files. It will attempt to modify the system :envvar:`PATH` environment variable to include this install location, but be sure to validate this on your configuration.
Note that most settings with environment variables support those variables because their default setting specifies the variable. If you override them, the environment variable will no longer work, unless you override it with another one. For example, the default value of ``confirm`` is literally ``%PYTHON_MANAGER_CONFIRM%``, which will resolve the variable at load time. If you override the value to ``yes``, then the environment variable will no longer be used. If you override the value to ``%CONFIRM%``, then that environment variable will be used instead.
True to use hard links for global shortcuts to save disk space. If false, each shortcut executable is copied instead. After changing this setting, you must run ``py install --refresh --force`` to update existing commands. By default, true. Disabling this may be necessary for troubleshooting or systems that have issues with file links.
Registry location to read and write PEP 514 entries into. By default, :file:`HKEY_CURRENT_USER\\Software\\Python`.
Start menu folder to write shortcuts into. By default, ``Python``. This path is relative to the user's Programs folder.
Path to the active virtual environment. By default, this is ``%VIRTUAL_ENV%``, but may be set empty to disable venv detection.
By default, the Python install manager will use your system-wide proxy settings, including automatic authentication. For most users, this behaves the same as your browser and other applications.
Setting ``NO_PROXY`` to any non-empty value will disable the use of any proxy. Use this to bypass your system's default proxy setting and attempt to access the index server directly.
Setting ``HTTPS_PROXY`` to a string like ``example.com:8080`` will connect to that proxy server for all HTTPS connections. For the default index, all connections will be using HTTPS, and so this is the usual setting to override.
The ``HTTP_PROXY`` variable may be needed if you are using a private index server that does not use encrypted connections, but does require the default proxy server to be overridden. It follows the same format as ``HTTPS_PROXY``.
The Company is optional and defaults to ``PythonCore``. It may contain slashes, while the rest may not, and so the last forward slash or backslash separates it from the Tag. When omitting Company, also omit any slash. In general, Company is matched as a prefix.
After filtering, runtimes are ordered by their primary tag and then the best is selected. "Best" is very context sensitive, and may be influenced by user configuration (such as the default tag), active virtual environments, prerelease marks on a runtime's sortable version, and whether a windowless interpreter is desired (such as launching through ``pyw.exe`` instead of ``py.exe``).
If your Python install manager does not seem to be working correctly, work through these tests and fixes to see if it helps. If not, report an issue at `our bug tracker <https://github.com/python/pymanager/issues>`_, including any relevant log files (written to your :file:`%TEMP%` directory by default).
Click Start, open "Manage app execution aliases", and check that the aliases for "Python (default)" are enabled. If they already are, try disabling and re-enabling to refresh the command. The "Python (default windowed)" and "Python install manager" commands may also need refreshing.
Ensure your :envvar:`PATH` variable contains the entry for ``%UserProfile%\AppData\Local\Microsoft\WindowsApps``. The operating system includes this entry once by default, after other user paths. If removed, shortcuts will not be found.
Click Start, open "Manage app execution aliases", and check that your ``python.exe`` alias is set to "Python (default)"
Check your :envvar:`PYTHON_MANAGER_DEFAULT` environment variable or ``default_tag`` configuration. The ``py list`` command will show your default based on these settings.
Installs that are managed by the Python install manager will be chosen ahead of unmanaged installs. Use ``py install`` to install the runtime you expect, or configure your default tag.
Prerelease and experimental installs that are not managed by the Python install manager may be chosen ahead of stable releases. Configure your default tag or uninstall the prerelease runtime and reinstall it using ``py install``.
A default ``._pth`` file is included, which further restricts the default search paths (as described below in :ref:`windows_finding_modules`). This file is intended for embedders to modify as necessary.
To select a particular version, add a ``-Version 3.x.y``. The output directory may be changed from ``.``, and the package will be installed into a subdirectory. By default, the subdirectory is named the same as the package, and without the ``-ExcludeVersion`` option this name will include the specific version installed. Inside the subdirectory is a ``tools`` directory that contains the Python installation:
Python UTF-8 mode is now enabled by default (:pep:`686`).
Windows still uses legacy encodings for the system encoding (the ANSI Code Page). When the :ref:`Python UTF-8 Mode <utf8-mode>` is disabled, Python uses the ANSI Code Page as the default encoding of text files, as returned by :func:`locale.getencoding`.
The :ref:`Python UTF-8 Mode <utf8-mode>`, enabled by default, ignores the system encoding and uses UTF-8 as the default text encoding. When the :ref:`UTF-8 mode <utf8-mode>` is enabled, you can still use the system encoding (the ANSI Code Page) via the "mbcs" codec.
Adding ``PYTHONUTF8={0,1}`` to the default environment variables will affect all Python 3.7+ applications on your system. If you have any Python 3.7+ applications which rely on the legacy system encoding, it is recommended to set the environment variable temporarily or use the ``-X utf8`` command line option.
Even when UTF-8 mode is disabled, Python uses UTF-8 by default on Windows for:
Additional "application paths" can be added in the registry as subkeys of :samp:`\\SOFTWARE\\Python\\PythonCore\\{version}\\PythonPath` under both the ``HKEY_CURRENT_USER`` and ``HKEY_LOCAL_MACHINE`` hives. Subkeys which have semicolon-delimited path strings as their default value will cause each path to be added to :data:`sys.path`. (Note that all known installers only use HKLM, so HKCU is typically empty.)
If the Python Home cannot be located, no :envvar:`PYTHONPATH` is specified in the environment, and no registry entries can be found, a default path with relative entries is used (for example, ``.\Lib;.\plat-win``).
If Python can't find its home and there are no registry values (frozen .exe, some very strange installation setup) you get a path with some default, but relative, paths.
Four Python |version| installers are available for download - two each for the 32-bit and 64-bit versions of the interpreter. The *web installer* is a small initial download, and it will automatically download the required components as necessary. The *offline installer* includes the components necessary for a default installation and only requires an internet connection for optional features. See :ref:`install-layout-option` for other ways to avoid downloading during installation.
All of the options available in the installer UI can also be specified from the command line, allowing scripted installers to replicate an installation on many machines without user interaction. These options may also be set without suppressing the UI in order to change some of the defaults.
Default
Bawaan
DefaultAllUsersTargetDir
DefaultAllUsersTargetDir
The default installation directory for all-user installs
DefaultJustForMeTargetDir
DefaultJustForMeTargetDir
The default install directory for just-for-me installs
DefaultCustomTargetDir
DefaultCustomTargetDir
The default custom install directory displayed in the UI
For example, to silently install a default, system-wide Python installation, you could use the following command (from an elevated command prompt)::
Customizing default Python versions
If no version qualifiers are found in a command, the environment variable :envvar:`!PY_PYTHON` can be set to specify the default version qualifier. If it is not set, the default is "3". The variable can specify 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 only available with the launcher included with Python 3.7 or newer.)
In addition to environment variables, the same settings can be configured in the .INI file used by the launcher. The section in the INI file is called ``[defaults]`` and the key name will be the same as the environment variables without the leading ``PY_`` prefix (and note that the key names in the INI file are case insensitive.) The contents of an environment variable will override things specified in the INI file.
[defaults]
python=3.7
[defaults]
python=3
python3=3.7