How to Check Python Version

Python is one of the most popular programming languages in the world. It is used for web development, data analysis, scientific computing, artificial intelligence, and more.
This article explains how to use the command line to check what version of Python is installed on your Linux, macOS, or Windows machine. Knowing the installed version is important when deploying applications that require a specific Python version.
We will also show you how to programmatically determine the Python version from within a running script, useful when you need to verify that the script supports the version installed on the user’s machine.
Python Versioning
Python uses semantic versioning . Production-ready releases follow this scheme:
MAJOR.MINOR.MICROFor example, in Python 3.13.1, 3 is the major version, 13 is the minor version, and 1 is the micro version.
MAJOR- Python has two major versions that are not fully compatible: Python 2 and Python 3. For example,3.11.6,3.12.4, and3.13.1are all part of the Python 3 major version.MINOR- These releases bring new features and functions. For example,3.12.0,3.12.1, and3.12.4are all part of the Python 3.12 minor version.MICRO- New micro versions contain bug fixes and improvements.
Development releases have additional qualifiers. For more information, read the Python “Development Cycle” documentation.
Checking Python Version
Python is pre-installed on most Linux distributions and macOS. On Windows, you need to download and install it separately.
To find out which version of Python is installed on your system, run the python3 --version or python3 -V command:
python3 --versionPython 3.13.1You can also use the short flag:
python3 -VOn some systems, the python command still points to Python 2. Always use python3 explicitly to ensure you are checking the Python 3 installation:
python --version
python3 --versionIf both commands return different versions, your system has both Python 2 and Python 3 installed. On modern systems, Python 2 is rarely present, but it is worth checking.
To check if Python 2 is still installed, run:
python2 --versionPython 2.7.18Checking Python Version in a Virtual Environment
When working inside a virtual environment , always check the version after activating it; the active environment may use a different Python binary than the system default:
source venv/bin/activate
python --versionPython 3.12.4The virtual environment’s python command points to whichever Python version was used to create it. For a full guide on creating and managing virtual environments, see Python Virtual Environments: venv and virtualenv
.
Programmatically Checking Python Version
The sys
module available in all Python versions provides system-specific parameters and functions. sys.version_info returns a tuple
containing five version numbers: major, minor, micro, releaselevel, and serial.
Let us say you have a script that requires at least Python 3.11. You can check that at runtime and exit early if the requirement is not met:
import sys
if not (sys.version_info.major == 3 and sys.version_info.minor >= 11):
print("This script requires Python 3.11 or higher!")
print("You are using Python {}.{}.".format(sys.version_info.major, sys.version_info.minor))
sys.exit(1)If you run the script using a Python version less than 3.11, it will produce the following output:
This script requires Python 3.11 or higher!
You are using Python 3.9.To print the full version string from within a script, use sys.version:
import sys
print(sys.version)3.13.1 (main, Dec 3 2024, 17:59:52) [GCC 13.2.0]Quick Reference
| Command | Description |
|---|---|
python3 --version | Check the Python 3 version |
python3 -V | Short flag, same result |
python --version | Check the default python binary version |
python2 --version | Check if Python 2 is installed |
python3 -c "import sys; print(sys.version)" | Print full version string from the command line |
source venv/bin/activate && python --version | Check version inside a virtual environment |
FAQ
How do I check the Python version in Linux?
Run python3 --version in the terminal. This prints the installed Python 3 version. If you have multiple versions installed, you may also try python --version to see which version the default python command points to.
What is the difference between python and python3?
On many Linux distributions, python historically pointed to Python 2 and python3 pointed to Python 3. On modern systems, python may point to Python 3 or may not exist at all. Use python3 explicitly to avoid ambiguity.
How do I check the Python version from inside a script?
Import the sys module and read sys.version_info. For example: print(sys.version_info.major, sys.version_info.minor). This is useful for writing version guards that exit early with a clear error message.
How do I check which Python version a virtual environment is using?
Activate the virtual environment with source venv/bin/activate, then run python --version. The version shown is the one the environment was created with.
What is the latest version of Python?
Check the official Python downloads page
for the latest stable release and release notes. Python versions change regularly, so the official page is the most reliable source.
Conclusion
The quickest way to check your Python version is python3 --version in the terminal. For scripts that depend on a minimum version, use sys.version_info to check at runtime and exit with a clear message if the requirement is not met. To install or update Python, see the official Python downloads page
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page