How to Check Your Python Version (Windows, macOS, Linux)
Published on
Updated on
To check your Python version, open a terminal and run:
python --versionIf that prints something like Python 3.12.4, you're done. If it errors or shows Python 2, try python3 --version (macOS/Linux) or py --version (Windows). That's the whole answer — the rest of this guide covers the platform differences, checking the version from inside a script, and fixing the "python is not recognized" error.
| Where you are | Command to run |
|---|---|
| Windows (CMD / PowerShell) | py --version or python --version |
| macOS / Linux terminal | python3 --version |
| Inside a running script | import sys; print(sys.version) |
| Jupyter / IPython | !python --version or import sys; sys.version |
| Checking a package instead | pip show <package> |
Check the Python version on the command line
Windows
Open Command Prompt or PowerShell and run:
py --versionThe py launcher ships with the official Windows installer and finds your installed Pythons even when they are not on PATH. python --version also works if Python was added to PATH during installation. To list every version installed:
py -0macOS
python3 --versionOn macOS, the bare python command either doesn't exist (modern macOS) or historically pointed to the system's legacy Python 2 — so make a habit of typing python3.
Linux (Ubuntu, Debian, Fedora, ...)
python3 --versionMost distributions ship python3. Whether plain python exists depends on the distro: on Ubuntu it appears only if the python-is-python3 package is installed.
Version of the active virtual environment
Inside an activated venv or conda environment, python --version always reports that environment's interpreter, which may differ from your system Python:
python --version # version of the active environment
which python # macOS/Linux: path of the interpreter answering
where python # Windows: same ideaIf a package "requires Python ≥ 3.10" but your code fails, check the environment that actually runs the code, not the system default.
Check the Python version in a script
Use sys.version_info when your code needs to make decisions, and platform.python_version() when you want a clean printable string:
import sys
print(sys.version) # full string, e.g. '3.12.4 (main, ...) [GCC 13.2]'
print(sys.version_info) # structured: sys.version_info(major=3, minor=12, ...)import platform
print(platform.python_version()) # '3.12.4'Enforce a minimum version
sys.version_info is a tuple, so it compares naturally:
import sys
if sys.version_info < (3, 10):
raise SystemExit("This script requires Python 3.10 or newer")This pattern is what modern projects use instead of the old Python 2 vs 3 branching — Python 2 reached end of life in 2020, so new code should simply assert a minimum 3.x version.
Fix: "python is not recognized" / "command not found"
If python --version fails, it means the shell can't find a Python executable — not necessarily that Python isn't installed.
- Try the alternatives first:
python3 --version(macOS/Linux) orpy --version(Windows). - Windows: if
pyworks butpythondoesn't, Python wasn't added toPATHduring installation. Re-run the installer and tick "Add python.exe to PATH", or just usepy. - Beware the Microsoft Store stub: on Windows, typing
pythonwith nothing installed opens the Microsoft Store.py --versionfailing too means Python genuinely isn't installed. - macOS/Linux: if
python3is also missing, install it via python.org (opens in a new tab), Homebrew (brew install python), or your distro's package manager.
Check the version of a package or library
The "version" questions people search often turn out to be about a library, not the interpreter. For any installed package:
pip show numpyOr from inside Python (works for most modern packages):
import numpy
print(numpy.__version__)For an overview of everything installed in the current environment: pip list.
Why the Python version matters
- Package compatibility — libraries like NumPy and Pandas drop old Python versions on a schedule; installs fail or silently resolve to old releases on outdated interpreters.
- Syntax availability —
matchstatements need 3.10+, modern type-hint syntax likelist[int]needs 3.9+, f-strings need 3.6+. - Multiple interpreters coexist — system Python, pyenv/conda versions, and per-project venvs can all answer to different commands, which is how "but it works in my terminal" bugs happen.
If your version turns out to be older than what you need, see how to upgrade Python — and consider a virtual environment per project so upgrades stop being global events.
FAQ
What is the fastest way to check my Python version?
Open a terminal and run python --version. If that fails, run python3 --version on macOS/Linux or py --version on Windows.
How do I check the Python version without a terminal?
Start any Python REPL or notebook — the version is printed in the banner. Or run import sys; print(sys.version) in any Python environment, including Jupyter.
Why do python --version and python3 --version show different versions?
They are different executables. python and python3 can point to different interpreters installed side by side. Use which python (macOS/Linux) or where python (Windows) to see which file each command runs.
How do I check which Python version a virtual environment uses?
Activate the environment, then run python --version. The active environment's interpreter always answers first while activated.
How do I require a minimum Python version in my code?
Compare against sys.version_info, e.g. if sys.version_info < (3, 10): raise SystemExit("Python 3.10+ required").
Related guides
- How to upgrade Python to the latest version
- Python virtual environments explained
- What is
__pycache__in Python?
Exploring dataframes in a notebook? PyGWalker (GitHub (opens in a new tab)) is an open-source Python library that turns your pandas or polars dataframe into a Tableau-like visual exploration UI — one import, no plotting code.