How to Check Python Version

By 

•

Updated on

•

8 min read

Cartoon green snake next to the text check python version

Before you install a package, run a script from a tutorial, or deploy an application, you need to know which Python version is on the machine. Many libraries require a minimum version, and code written for a newer release may fail on an older interpreter.

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. The article also covers how to find the active interpreter and other Python commands available through your PATH.

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 release numbers follow a three-part scheme. Production-ready releases look like this:

txt
MAJOR.MINOR.MICRO

For 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, and 3.13.1 are all part of the Python 3 major version.
  • MINOR - These releases bring new features and functions. They can also remove features deprecated in earlier releases. Unlike semantic versioning, a minor version bump does not guarantee backward compatibility. For example, 3.12.0, 3.12.1, and 3.12.4 are 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.

Tip
Python 2 reached end of life in January 2020 and is no longer supported. All new projects should use Python 3.

Checking Python Version

Most Linux distributions ship with Python 3 pre-installed. On macOS, the python3 command becomes available after you install the Xcode Command Line Tools. The first time you run it, macOS offers to install them for you.

To find out which version of Python is installed on your system, run the python3 --version or python3 -V command:

Terminal
python3 --version
output
Python 3.13.1

You can also use the short flag:

Terminal
python3 -V

To see how the interpreter was built, pass the -V flag twice:

Terminal
python3 -VV
output
Python 3.13.1 (main, Dec  3 2024, 17:59:52) [GCC 13.2.0]

The output includes the build date and the compiler used to build the interpreter. This is useful when you report a bug or compare two installations of the same version.

On some systems, the python command still points to Python 2. Always use python3 explicitly to ensure you are checking the Python 3 installation:

Terminal
python --version
python3 --version

Compare the major version reported by each command. If python reports 2.x and python3 reports 3.x, your system has both Python 2 and Python 3 installed. If both report 3.x but show different minor releases, your system has multiple Python 3 interpreters.

To check if Python 2 is still installed, run:

Terminal
python2 --version
output
Python 2.7.18

Finding Where Python Is Installed

A system can have more than one Python interpreter. To see which one runs when you type python3, use the which command:

Terminal
which python3
output
/usr/bin/python3

The output shows the path to the first python3 binary found in your PATH.

To show every python3 command that Bash or Zsh can find in your PATH, use type -a:

Terminal
type -a python3
output
python3 is /usr/local/bin/python3
python3 is /usr/bin/python3

The first path is the interpreter your shell runs. The remaining paths are other python3 commands available through your PATH.

To inspect the versioned Python 3 commands in /usr/bin, run:

Terminal
ls /usr/bin/python3*
output
/usr/bin/python3  /usr/bin/python3.13

The versioned entry lets you check that interpreter directly. Versions installed from a PPA get their own command in /usr/bin, such as python3.14. Versions built from source usually go to /usr/local/bin. You can check each one by calling it by name:

Terminal
python3.14 --version

Checking Python Version on Windows

On Windows, open PowerShell or Command Prompt and run:

powershell
python --version

If the command opens the Microsoft Store instead of printing a version, Windows resolved an app execution alias rather than a working interpreter. Python may not be installed, or the alias and PATH settings may need correction. Open Manage app execution aliases and check that the selected Python installation is available through your PATH.

Python 3.14 introduced the Python install manager. It provides the py command. To list every Python version it manages, run:

powershell
py list

To print the executable path for each detected runtime, use the exe output format:

powershell
py list --format=exe

This prints one executable path per runtime, which makes multiple Windows installations easier to distinguish. On systems that still use the older Python launcher, use py -0 to list versions or py -0p to include their paths.

Checking 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. On Linux or macOS, run:

Terminal
source venv/bin/activate
python --version
output
Python 3.12.4

In PowerShell on Windows, activate the environment and check its version with:

powershell
.\venv\Scripts\Activate.ps1
python --version

In Command Prompt, use venv\Scripts\activate.bat instead of the first command. Both forms make python --version query the virtual environment’s interpreter.

The 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 .

When the interpreters come from uv rather than from your distribution, uv python list reports every version it has installed along with the ones it can download.

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 components: 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:

py
import sys

if sys.version_info < (3, 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)

Comparing sys.version_info to a tuple checks the major and minor version in one step.

If you run the script using a Python version less than 3.11, it will produce the following output:

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:

py
import sys
print(sys.version)
output
3.13.1 (main, Dec  3 2024, 17:59:52) [GCC 13.2.0]

Quick Reference

CommandDescription
python3 --versionCheck the Python 3 version
python3 -VShort flag, same result
python3 -VVShow the version with build details
which python3Show the path of the active python3 binary
type -a python3Show every python3 command in your PATH
py listList installed Python versions on Windows
py list --format=exeList Python interpreter paths on Windows
python --versionCheck the default python binary version
python2 --versionCheck 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 --versionCheck a virtual environment on Linux or macOS
.\venv\Scripts\Activate.ps1; python --versionCheck a virtual environment in PowerShell

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?
On Linux or macOS, activate the environment with source venv/bin/activate. In PowerShell, use .\venv\Scripts\Activate.ps1; in Command Prompt, use venv\Scripts\activate.bat. 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

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

View author page