Python is a popular programming language used for everything from web development to data science. But sometimes, you need to find Python version installed on your system. Different versions bring new features, bug fixes, and security updates, making it essential to check Python version before running your projects. Knowing your Python version ensures compatibility with libraries and frameworks. Some applications require specific versions, and using the wrong one can cause errors.
This guide will show you how to check Python version on Windows, macOS, and Linux using simple commands. Whether you need to check which version of Python is installed, get Python version in a script, or find the right Python version command, we’ve got you covered.
Checking Python Version on Windows
If you're using Windows, follow these steps:
-
Open the Command Prompt (Press
Win + R
, typecmd
, and hit Enter). -
Type the following command and press Enter:
python --version
Or use:
python -V
-
If Python is installed, you’ll see output like this:
Python 3.10.4
If the command doesn’t work, try:
python3 --version
Or:
py --version
Checking Python Version on macOS
For macOS users:
-
Open Terminal (press
Cmd + Space
, typeTerminal
, and hit Enter). -
Run:
python3 --version
Since macOS often comes with Python 2 pre-installed, using
python
might show an outdated version.
To verify all installed versions, use:
ls /usr/bin/python*
Checking Python Version on Linux
Most Linux distributions come with Python pre-installed. To check:
-
Open Terminal.
-
Type:
python3 --version
Or:
python -V
On some systems, python
may refer to Python 2, while python3
points to Python 3.
Python Version Commands
Command | Description |
---|---|
python --version | Displays Python version (Windows/Linux) |
python3 --version | Checks Python 3 version (macOS/Linux) |
py --version | Works on Windows to show the version |
How to Check Python Version in a Script
Sometimes, you need to check Python version inside a script. These methods are useful when debugging or ensuring compatibility in your code. Here are some ways:
Using sys Module
import sys print("Python version:", sys.version)
Using platform Module
import platform print("Python version:", platform.python_version())