How can I check my python version in cmd?

Learn how can i check my python version in cmd? with practical examples, diagrams, and best practices. Covers python, version development techniques with visual explanations.

How to Check Your Python Version in Command Prompt (CMD)

A command prompt window displaying Python version information, with a Python logo subtly in the background.

Learn various methods to quickly and accurately determine the Python version installed on your Windows system using the Command Prompt.

Knowing your Python version is crucial for development, debugging, and ensuring compatibility with libraries and frameworks. This article guides you through several straightforward methods to check your Python version directly from the Windows Command Prompt (CMD), covering common scenarios and potential issues.

Method 1: Using the python --version Command

The most common and direct way to check your Python version is by using the --version flag with the python command. This command queries the Python executable found in your system's PATH environment variable.

python --version

Checking Python version using the --version flag

Method 2: Using the python -V (Capital V) Command

Similar to --version, the -V (capital V) flag also works to display the Python version. This is an older, but still widely supported, convention.

python -V

Checking Python version using the -V flag

Method 3: Using the Python Launcher (py)

If you have multiple Python versions installed (e.g., Python 2.7 and Python 3.9), the Python Launcher (py.exe) is a convenient tool that allows you to specify which version to use. It's automatically installed with Python on Windows.

py --version
py -V

Checking default Python launcher version

To check a specific Python 3.x version, you can use py -3 --version. For Python 2.x, use py -2 --version.

py -3 --version
py -2 --version

Checking specific Python versions using the launcher

Method 4: Checking Python Version Interactively

You can also launch the Python interpreter directly in CMD and then query the version from within the interactive shell. This is useful if you want to confirm the version of the interpreter you're currently interacting with.

python
import sys
print(sys.version)

Checking Python version from within the interactive shell

Troubleshooting: 'python' is not recognized

If you encounter the error "'python' is not recognized as an internal or external command, operable program or batch file," it means Python is not correctly added to your system's PATH environment variable. This is a common issue, especially after a manual installation.

A flowchart showing troubleshooting steps for 'python is not recognized' error. Steps include: 'Check PATH variable', 'Reinstall Python (add to PATH)', 'Use full path to python.exe'.

Troubleshooting flow for 'python is not recognized' error

1. Verify Python Installation

First, ensure Python is actually installed on your system. Look for a 'Python' folder in C:\Program Files or C:\Users\YourUser\AppData\Local\Programs\Python.

2. Add Python to PATH (Manual)

If Python is installed but not in PATH, you'll need to add its installation directory (e.g., C:\Python39 and C:\Python39\Scripts) to your system's PATH environment variable. Search for 'Environment Variables' in Windows, then edit the 'Path' variable under 'System variables'.

The easiest fix is often to reinstall Python. During installation, make sure to check the box that says "Add Python X.X to PATH" on the first screen of the installer.