How can I check my python version in cmd?
Categories:
How to Check Your Python Version in Command Prompt (CMD)
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
py
launcher (see Method 3).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
python
and pressing Enter, you will enter the Python interactive shell. Type import sys
and then print(sys.version)
to see the full version string. To exit the shell, type exit()
and press Enter, or press Ctrl+Z
followed by Enter.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.
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'.
3. Reinstall Python (Recommended)
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.