Sub topic 2
Choosing a Python version
This chapter assumes you can open a terminal and run a command, and that you have installed software on your operating system before. You don't need to know Python yet. By the end you will be able to read a version number, decide which release to install, and check whether a project's requirements match what you have.
What a version number tells you
A Python version has three parts, such as 3.13.2:
- Major (3): Python 3 is the only major line in use. Python 2 reached end of life on January 1, 2020 and gets no fixes of any kind. Treat any tutorial or tool that needs Python 2 as obsolete.
- Minor (13): This is the feature release. It adds language features and library changes, and it can remove deprecated behavior. When people say "Python 3.13", they mean this level.
- Micro (2): This is a maintenance release. It contains bug and security fixes only and is safe to upgrade to within the same minor version.
The minor version is the one that matters when you choose. Code written for 3.13 may use syntax that 3.9 can't parse. Libraries also publish builds for specific minor versions, so a library may not have a build for a release that came out last month.
The release cycle
Since Python 3.9, a new minor version has been released every year, in October. Each one follows a predictable path:
- Pre-release (alpha, beta, release candidate): Roughly May to October of the year before the final release. These builds are for testing and are not for real projects.
- Bugfix phase: About two years of regular releases that fix bugs and security problems.
- Security-only phase: About three more years in which only security fixes are made. Source is released, and installers may not be.
- End of life: After five years in total, the version gets no fixes at all.
The dates below are the planned end-of-life months. Check the "Status of Python versions" page on python.org for the current table, because schedules and releases move.
| Version | Planned end of life | Notes |
|---|---|---|
| 3.10 | October 2026 | Reaches or has reached end of life. Avoid for new work. |
| 3.11 | October 2027 | Still supported. Fine if a project requires it. |
| 3.12 | October 2028 | Widely supported by libraries. |
| 3.13 | October 2029 | Introduced experimental free-threaded and JIT builds. |
| 3.14 | October 2030 | Newest feature set in this table. |
A release newer than 3.14 may exist by the time you read this. If you see one, apply the same rules from the next section to it.
How to decide
For a new, personal project with no outside constraints, install a recent stable release. In practice, that is the newest minor version that has been out for a few months, or the one before it. This gives you the longest support window and the newest language features.
The usual rule has two parts:
- Not the newest, if you rely on many libraries. A library with compiled code (for example in data science or machine learning) can take weeks or months after October to publish builds for a new minor version. If
pip installfails on a brand-new release, that is the likely cause. - Not close to end of life. A version with a year or less of support left will force an upgrade soon.
Use the constraint that already exists
If you are joining an existing project, don't choose. Look for a declared requirement. Common places are:
requires-pythoninpyproject.toml.- A
.python-versionfile, which version managers such as pyenv and uv read. - A "Python versions" section in the README or in the CI configuration.
A requires-python entry looks like this:
[project]
name = "example"
version = "0.1.0"
requires-python = ">=3.10">=3.10 means 3.10 or any later version works. It sets a minimum, not a recommendation. If you have a choice inside the range, take a supported version near the upper end.
Checking which version you have
You can check from the shell. The command name differs by platform, which the next chapters cover in detail.
python3 --version
# On Windows, use: py --versionYou can also check from inside a script. This is useful when your code needs a minimum version and should fail with a clear message instead of a confusing syntax error. Save it as version_check.py:
import sys
MINIMUM = (3, 10)
if sys.version_info < MINIMUM:
needed = ".".join(str(part) for part in MINIMUM)
raise SystemExit(f"Python {needed} or newer is required.")
info = sys.version_info
print(f"Running Python {info.major}.{info.minor}.{info.micro}")sys.version_info is a tuple-like object, so comparing it with a plain tuple such as (3, 10) works as you would expect. Don't compare version strings: "3.9" > "3.10" is true when comparing text, which is wrong.
A script that uses newer syntax can't run this check on an older interpreter. Python parses the whole file before running it, so a syntax error appears first. Keep the check in a small entry file that uses only old syntax.
Edge cases and gotchas
The system Python is not yours. macOS and many Linux distributions ship a Python that their own tools depend on. Its version may be old, and on Linux, installing packages into it can be blocked on purpose (to protect the system). Install your own Python for development, and use virtual environments, which a later chapter explains.
Several versions can live side by side. Installing 3.13 does not have to remove 3.11. Each minor version installs to its own location, and you pick one with a command such as python3.11 on macOS and Linux or py -3.11 on Windows. This is how you test one project against more than one version. A micro update (3.13.1 to 3.13.2) replaces the earlier one in the same minor line.
Pre-releases are not for daily use. Python.org lists alpha, beta, and release candidate builds next to stable ones. Their names carry a marker such as 3.15.0rc1. Library authors use them to test. You should not use them for work that matters.
Free-threaded builds are separate. Python 3.13 added an experimental build without the global interpreter lock (the lock that lets only one thread run Python code at a time), and 3.14 supports it officially. It is a separate installation option, not the default. Many compiled libraries don't support it yet. Skip it for a first install.
Newer is not always faster for you. Each release usually brings modest speed gains and clearer error messages. Don't upgrade only for speed. Upgrade when you need a feature, when support is ending, or when a library requires it.
Where the version is tied to a tool. Some tools pin the interpreter for you. A virtual environment records the version it was created from, so deleting the interpreter or upgrading it to a new minor version breaks that environment. You rebuild it with the new version instead of upgrading it in place.
A practical recommendation
For the rest of this tutorial, use the newest stable Python 3 release that python.org offers for your platform, or the one before it if you already have it installed. Every example here works on any supported release from 3.10 upward. If a command shows a version number in its output, yours may differ in the minor or micro part and that is fine.
Exercise
A teammate's project has requires-python = ">=3.11" in pyproject.toml. You have Python 3.10.12 installed and Python 3.13 is the newest stable release. Which version should you install, and why? Also explain why a check like "3.9" > "3.10" can't be used to compare versions.
Show answer
Install 3.13 (or another supported release at 3.11 or higher). The 3.10.12 interpreter is below the declared minimum, so the project may fail on it. If the project's libraries don't yet publish builds for 3.13, choose 3.12 or 3.11 instead, since both satisfy ">=3.11". The string comparison fails because strings are compared character by character: "9" is greater than "1", so "3.9" sorts after "3.10" even though 3.10 is the newer release. Compare sys.version_info with a tuple of integers, such as (3, 10), instead.