Guides

How to check the Python version on Windows, Linux and macOS, and in code

How to check Python version: python3 --version on Linux and macOS, py --version in cmd, sys.version_info in code, plus venvs, pip and several versions.

Published ~7 min read
On this page

Short answer: run python3 --version on Linux and macOS, or py --version (or python --version) on Windows. It prints a line such as Python 3.11.2. Inside a script, sys.version_info gives the version as numbers you can compare, for example sys.version_info >= (3, 10). If the command is not found, Python is missing or installed under another name.

Linux · macOS
python3 --version
python3 -c "import sys; print(sys.version)"
Windows (cmd or PowerShell)
py --version
python --version
Output on Debian 12
$ python3 --version
Python 3.11.2
$ python3 -c "import sys; print(sys.version)"
3.11.2 (main, Oct  7 2026, 12:35:07) [GCC 12.2.0]

-V is the short form of --version. On Debian and Ubuntu, plain python --version usually answers python: command not found, because these systems install the interpreter only as python3; that is a naming question, not a missing Python, and python: command not found sorts it out.

Every way to check the Python version

WhereCommandPrints
Linux, macOSpython3 --versionPython 3.11.2
Linux, macOS, with build detailspython3 -VVVersion, build date, compiler
Windowspy --versionThe version the py launcher picks
Windows, every installed versionpy -0pVersions and paths (classic py launcher)
Windows, Python install managerpy listInstalled runtimes
Inside Pythonsys.version_infoA tuple you can compare
Inside Python, as textplatform.python_version()'3.11.2'
Which file runstype -a python3Every python3 on the PATH
A virtual environment.venv/bin/python --versionThe venv's version
The Python behind pippython3 -m pip --versionpip's version and its Python

How do I check the Python version on Linux and macOS?

python3 --version is enough for the version number. -VV (two capital Vs, Python 3.6 and later) adds the build, and two more commands show which file actually answers:

Debian 12
$ python3 -VV
Python 3.11.2 (main, Oct  7 2026, 12:35:07) [GCC 12.2.0]
$ type -a python3
python3 is /usr/bin/python3
python3 is /bin/python3
$ readlink -f /usr/bin/python3
/usr/bin/python3.11

The build date is when Debian last rebuilt its package, here for a security update, not when Python 3.11.2 came out: distributions keep patching the version they ship. type -a lists every match on the PATH in the order the shell tries them, and the first one wins. On Debian 12, /bin is a link to /usr/bin, so the same file shows up twice. readlink -f follows the symlink to the real interpreter. To see every version installed side by side:

Linux
ls /usr/bin/python3* /usr/local/bin/python3* 2>/dev/null

On macOS, /usr/bin/python3 belongs to Apple’s Command Line Tools; if they are not installed, running it opens a prompt offering to install them instead of printing a version. Homebrew’s Python lives in /opt/homebrew/bin on Apple Silicon, and which -a python3 in zsh shows which of the two comes first.

How do I check the Python version in cmd or PowerShell?

cmd or PowerShell
python --version
py --version
py -0p
where.exe python
  • py --version asks the Python launcher, which python.org installs. It works even when python is not on the PATH, and with several versions installed it reports the one it would start by default.
  • py -0p (py -0 without paths) lists every Python the classic launcher knows, with the default marked by an asterisk. With the newer Python install manager that python.org offers since Python 3.14, the command is py list.
  • where.exe python shows which python.exe files are on the PATH, in order. A first hit under AppData\Local\Microsoft\WindowsApps is Windows’ Store shortcut, not a real Python: it answers with “Python was not found; run without arguments to install from the Microsoft Store”. The Windows section of the not-found guide explains how to switch it off.

In PowerShell, type where.exe in full: plain where is an alias for Where-Object there. (Get-Command python).Source prints the path of the first match as well.

How do I get the Python version inside a script?

Python
import sys
import platform

print(sys.version)                # full text, for logs and bug reports
print(sys.version_info)           # named tuple, for comparisons
print(sys.version_info[:2])       # just major and minor
print(platform.python_version())  # 'X.Y.Z' as a string
print(sys.executable)             # the interpreter file that runs this code
Output with python3 on Debian 12
3.11.2 (main, Oct  7 2026, 12:35:07) [GCC 12.2.0]
sys.version_info(major=3, minor=11, micro=2, releaselevel='final', serial=0)
(3, 11)
3.11.2
/usr/bin/python3

sys.version_info is the one to compare against, because tuples compare number by number. Comparing version strings goes wrong as soon as the minor version has two digits: "3.9" > "3.10" is True, since text compares character by character and 9 sorts after 1. The fields also have names: sys.version_info.major and sys.version_info.minor. In a Jupyter notebook or an editor, sys.executable is the quickest way to see which interpreter the kernel really uses, which is often not the one your terminal finds.

A minimal version guard

guard.py
import sys

if sys.version_info < (3, 10):
    sys.exit(f"This script needs Python 3.10 or newer, found {sys.version.split()[0]}")

# the rest of the script

sys.exit() with a string prints it to stderr and ends the script with exit status 1, so a shell script or a CI job sees the failure. Raised to (3, 12) and run with Debian 12’s Python 3.11, it does exactly that:

Debian 12, Python 3.11.2
$ python3 guard.py
This script needs Python 3.12 or newer, found 3.11.2
$ echo $?
1

One limit: Python parses the whole file before running its first line, so a guard cannot save a file that uses syntax the old interpreter does not know (a match statement on 3.9, say). That ends in a SyntaxError before the check runs. Keep the guard in a small entry file that imports the rest, and for a package, declare requires-python = ">=3.10" in pyproject.toml so pip refuses to install it on an older Python in the first place.

How do I check if Python is installed?

Linux · macOS
command -v python3 && python3 --version || echo "Python 3 is not installed"

With Python present this prints its path and version (/usr/bin/python3, then Python 3.11.2 on Debian 12); with no python3 on the PATH it prints the message. On Windows, py --version is the reliable test, because the Store shortcut makes python look present when it is not. Installing it is covered per system in the not-found guide.

Several Python versions: which one runs?

python3 is the distribution’s default. Extra versions, from the distribution, pyenv, uv or a source build, sit next to it under versioned names such as python3.12, and you call them by that name: python3.12 --version. The way to use one for a project is a virtual environment created from it (python3.12 -m venv .venv); the not-found guide lists where to get other versions.

Which Python version does a virtual environment use?

Linux · macOS
.venv/bin/python --version
cat .venv/pyvenv.cfg
pyvenv.cfg of a venv made with python3 on Debian 12 (command line shortened)
home = /usr/bin
include-system-site-packages = false
version = 3.11.2
executable = /usr/bin/python3.11
command = /usr/bin/python3 -m venv /path/to/.venv

A venv is tied to the interpreter it was created from: its python is a link to that file, and version in pyvenv.cfg records it. On Windows the file is .venv\Scripts\python.exe. To test from code whether you are inside a venv at all, compare sys.prefix != sys.base_prefix: it is True in a venv and False for the system Python. When the system Python moves to a new minor version, as it does in an upgrade from Debian 12 to 13 (3.11 to 3.13), existing venvs stop working and need to be created again from the requirements file.

pip --version shows which Python pip belongs to

Debian 12
$ python3 -m pip --version
pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)

The bracket at the end names the Python that pip installs packages for. If bare pip --version shows a different Python than python3 --version, packages you install with pip will not be importable from python3. Use python3 -m pip from then on; the pip guide has the details of pip versus pip3.

Is my Python version still supported?

Each Python feature release gets about five years of upstream fixes, and the status of every branch is listed on the Python developer guide’s versions page (devguide.python.org/versions). As of October 2026, Python 3.9 and older no longer get upstream security fixes, and PEP 619 schedules the end of life of 3.10 for October 2026. A distribution’s own Python follows the distribution instead: Debian 12 keeps patching its 3.11 for as long as Debian 12 is supported, as the October 2026 build date above shows. So check the operating system too, with how to check the Linux version.

Which Python comes with each server image?

Imagepython3 version
Debian 133.13
Debian 123.11
Debian 113.9
Ubuntu 24.043.12
Ubuntu 22.043.10
Ubuntu 20.043.8

These are the Debian and Ubuntu releases you can pick for a Linux VPS at VMHeaven. If your app needs a newer Python than the image ships, choose a newer image (Ubuntu VPS 24.04 or Debian VPS 13), or install the version you need next to the system one and run the app from a venv built with it. Either way, python3 --version right after the first login tells you where you start.

Frequently asked

How do I check the Python version in cmd?

Run py --version or python --version in Command Prompt. py -0p lists every installed Python with its path (py list with the newer Python install manager). If python answers 'Python was not found', that is the Microsoft Store shortcut, not a real Python; where.exe python shows which file runs.

How do I get the Python version inside a script?

Import sys and read sys.version_info, a tuple such as (3, 11, 2, 'final', 0) that compares correctly: sys.version_info >= (3, 10). platform.python_version() returns the plain string '3.11.2', and sys.version the full text with build details. Do not compare version strings, because '3.9' > '3.10' is True.

How do I check if Python is installed?

On Linux and macOS, command -v python3 prints its path if it is installed, and python3 --version prints the version. On Windows, py --version is the reliable test, because the Microsoft Store shortcut makes python look installed when it is not.

Why do python and python3 show different versions?

They are different files: python may be Python 2, a virtual environment, pyenv or the Windows Store shortcut, while python3 is the distribution's Python 3. type -a python python3 (where.exe python on Windows) shows which file each name runs. Inside a project, use the virtual environment's python.

Related articles

All guides