How to use Python’s py launcher for Windows


The Windows version of the Python interpreter can be run from the command line the same way it’s run in other operating systems, by typing python or python3 at the prompt. But there’s a feature unique to the Python edition of Windows that makes it easier to manage multiple installed versions of the Python interpreter—the py launcher.

The py launcher—or just py for short—is a shortcut to all of the installed versions of Python on one’s system. With a command-line switch, you see at a glance all of the Python interpreters you’ve installed, and invoke a specific version of Python, whether 32-bit or 64-bit.

Install the py launcher

The py launcher is optionally installed during the setup process when you first install Python on Windows. At one point you’ll be prompted to do so, as per the screenshots shown below. There is no downside to having py installed. You can always run the Python interpreter directly instead, and py doesn’t interfere with other behaviors.

python install 01 IDG

When installing Python on Windows, select the “Customize installation” option during setup.

python install 02 IDG

In the next screen, make sure the “py launcher” option is checked.

When you type py at the command line, the launcher will invoke the current default Python interpreter. py by itself will drop you into the Python REPL, which you can exit as you normally would by typing quit() or Ctrl-Z.

To see which versions of Python are available to py, type py -0p. You’ll be presented with a list of all the known interpreters in the system, their version numbers, and their full paths. The interpreter marked with an asterisk is the default.

To invoke a specific edition of Python, type py followed by the switch in the left-hand column for the appropriate version. For instance, to launch the 64-bit edition of Python 3.9, you would type py -3.9-64.

Copyright © 2021 IDG Communications, Inc.



Source link