Problem
If you run Python in your terminal or shell, you may have realized that there are two ways to do so: using the “python
” command and using the “py
” command. What’s the difference?
Example
Say, you want to check your Python version. You can run both commands and the output is different!
Here’s using the “python
” command:
$ python -V 3.9.2
Here’s using the “py
” command:
$ py -V 3.8.5
You can see that running the two commands can execute different Python versions!
Difference “python” vs “py”
- The command
python
refers to the Python executable of the default Python installation. Technically, the path of this version is stored inside thePATH
environment variable where your OS will search for the executable when processing any command. - The command
py
refers to the Python launcher, a utility that’s automatically installed intoC:\Windows\
for any Python installation on Windows. All files in the Windows folder are accessible without needing to modify thePATH
environment variable. Thus, the Python launcher automatically delegates the work to the latest Python version installed in your environment. However, you can also specify the used installation by means of a flag argument such as inpy -3.6
to specify Python version 3.6.
Further Reading and References
Read more about the Python launcher in the docs and in this excellent SO post. Here’s an excerpt from the docs:
The Python launcher for Windows is a utility which aids in locating and executing of different Python versions. It allows scripts (or the command-line) to indicate a preference for a specific Python version, and will locate and execute that version.
Unlike the PATH
variable, the launcher will correctly select the most appropriate version of Python. It will prefer per-user installations over system-wide ones, and orders by language version rather than using the most recently installed version.