Appendix A: Python Launcher For Windows
The Python launcher for Windows is included in the standard Python distribution since the version 3.3. It is a version management software that is useful when multiple versions of the Python interpreter are installed on the same computer, and as its name suggests, it allows to launch a version among them.
The Python launcher can be installed for all users on your Windows system, or for the current user only. In the first case it will be installed in the Windows directory C:\Windows, while in the second case it will be installed under the AppData directory:
There are two executables for the Python launcher:
- py.exe, which allows to launch the python.exe interpreter. This latter is generally used to execute programs with a text-based output.
- pyw.exe, which allows to launch the pythonw.exe interpreter. This latter is generally used to execute programs with a graphical user interface (GUI).
In this section, we will only use the py.exe launcher. To start it you can either double-click it or use a command-line interpreter (CLI), which is a computer program that allows you to interact with the Windows operating system and start executable files. Windows comes with two native CLIs, which are Command Prompt and PowerShell. To open one of them, type its name in the search box of the Windows taskbar, then press the Enter key of your keyboard:
In the screenshot above, you can see the version of the Python interpreter, which is 3.9.5. You can also see the three greater-than signs >>> which indicate that the Python interpreter is launched and is ready to receive and execute your Python code.
To return to the PowerShell prompt, you can use either of these methods:
- Type exit() then press the Enter key.
- Type quit() then press the Enter key.
- Press CTRL+Z then press the Enter key.
Note: The pressing of the Enter key after any CLI command is necessary to execute this command. Therefore, from now on, the phrase “then press the Enter key” will be implied after any CLI command.
The .exe extension can be omitted from the py.exe command:
The list of Python interpreters installed on a given computer can be displayed using either of these commands: py -0 or py –list:
In the screenshot above, you can see that five versions of the Python interpreter are installed on the computer. These versions are 3.10 (64-bit), 3.9 (64-bit), 3.7 (64-bit), 3.7 (32-bit), and 2.7 (64-bit).
The list of installed Python interpreters, and their installation locations, can be displayed using either of these commands: py -0p or py –list-paths:
In the two screenshots above, there is an asterisk * next to the 3.9 version of the Python interpreter. This asterisk means that when you enter the py.exe (or py) command in the CLI, the default version of the Python interpreter that will be launched is the 3.9 version. The default version is always the latest stable release, not the latest installed release:
- “The latest stable release” means that alphas, betas, and release candidates cannot be elected as the default version. For example, in the screenshot below, the 3.10 release wasn’t elected as the default version (despite it is newer than the 3.9 release) because it is a beta release (the letter “b” in 3.10.0b1 stands for beta):
- “Not the latest installed release” means that if, for example, you install the 3.9 release then you install the 3.7, the 3.9 will remain the default version because it is newer than the 3.7, according to the Python Software Foundation releases.
If you want to launch a Python interpreter other than the default, you must specify its version as an argument to the py.exe (or py) command. Here are the possible arguments that can be used, and their meanings:
* If an X.Y version of the Python interpreter is installed with both 32 and 64-bit variants, the Python launcher will prefer to launch the 64-bit variant. To launch the 32-bit variant, you must add the -32 qualifier to the argument.
Here are some examples that demonstrate how the Python launcher can locate and launch multiple versions of the Python interpreter:
C:\> py -0
Installed Pythons found by py Launcher for Windows
-3.9-64 *
-3.7-64
-3.7-32
-3.10-64
-2.7-64
C:\> py -2
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:25:05) [MSC v.1500 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
C:\> py -3
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
C:\> py -3.10
Python 3.10.0b1 (tags/v3.10.0b1:ba42175, May 3 2021, 20:22:30) [MSC v.1928 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
C:\> py -3.7-32
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
PS C:\> py -3.7
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
C:\> py -3-32
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
C:\> py -3-64
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
The Python launcher for Windows can be uninstalled at any time. To do that, open the Control Panel of your Windows system and navigate to Programs and Features. Search and select the Python Launcher in the list of installed programs. Click the Uninstall button in the menu above the list of programs, or right-click the program and select Uninstall: