5 Best Ways to Check Python Version in Windows Command Line

πŸ’‘ Problem Formulation: Every Python developer, at some stage, needs to ascertain the version of Python installed on their Windows operating system. This is often a crucial step for environment setup, troubleshooting, and ensuring compatibility with Python packages. The desired output is a simple, clear indication of the installed Python version presented in the command line interface.

Method 1: Using python --version

Arguably the most common method to check the Python version on a Windows system is the python --version command. This straightforward command queries the Python executable to display the version information directly in the command line interface.

Here’s an example:

python --version

Output:

Python 3.8.5

This method is as simple as it gets. By typing python --version, you send a request to the python executable to output the current version you have installed. It’s a quick and surefire way to know your Python version without navigating through different menus or interfaces.

Method 2: Using python -V

The python -V command (note the capital ‘V’) serves the same purpose as the previously mentioned command but is an alternative that users might prefer due to its brevity. This command also returns the installed Python version.

Here’s an example:

python -V

Output:

Python 3.8.5

This code snippet is another simple and effective way to check your Python version. It’s similar to the previous method; however, it uses a capital ‘V’ as a shorthand argument, which some find quicker to type and remember.

Method 3: Using the Python Interactive Shell

By starting the Python interactive shell simply with the python command, one can see the version information displayed in the banner at launch. This is a more visual method for those who prefer immediate visual feedback as they interact with Python.

Here’s an example:

python

Output:

Python 3.8.5 (default, Jul 28 2020, 12:59:40) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Once you enter the python command, the interactive Python shell launches and automatically includes the version number in its initial greeting message. This method not only gives you the version number but also informs you about the build date and platform details.

Method 4: Using py -0

In Windows, when multiple versions of Python are installed, the py launcher can be used to manage these versions. The py -0 command (that’s a zero) lists all installed Python versions.

Here’s an example:

py -0

Output:

Installed Pythons found by py Launcher for Windows
 -3.8-64 *
 -2.7-64

When executed, py -0 provides a list of all Python interpreters recognized by the Windows launcher, along with an asterisk (*) next to the default interpreter. This is particularly useful for managing multiple Python installations.

Bonus One-Liner Method 5: Using Environment Variables

This method involves checking the Python version by navigating to the environment variables in the system properties window and finding the version number in the Python path variable. It is indirect but useful when command line access is not possible.

Here’s an example:

C:\Users\ExampleUser\AppData\Local\Programs\Python\Python38\

Output: The path shows that Python 3.8 is installed.

This method entails navigating through the Windows system settings to find the path variables where Python is installed. Despite being less straightforward, it’s a viable option if the command line isn’t accessible for some reason.

Summary/Discussion

  • Method 1: python --version. Simplicity. Universal applicability. Cannot differentiate between multiple installs without additional context.
  • Method 2: python -V. Quickness. As reliable as Method 1. Same limitations in multi-install scenarios.
  • Method 3: Python Interactive Shell. Provides version information with additional context. Can be slower than command line arguments, especially if not used for other purposes.
  • Method 4: py -0. Management of multiple versions. Best for environments with multiple Python installations. Not informative for single installs.
  • Bonus Method 5: Environment Variables Method. Non-command line approach. In-depth file path review. Indirect and may be time-consuming compared to command line methods.