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!
β₯οΈ Info: Are you AI curious but you still have to create real impactful projects? Join our official AI builder club on Skool (only $5): SHIP! - One Project Per Month
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
pythonrefers to the Python executable of the default Python installation. Technically, the path of this version is stored inside thePATHenvironment variable where your OS will search for the executable when processing any command. - The command
pyrefers 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 thePATHenvironment 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.6to 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.