Handle Python upgrade issues by upgrading in a fresh virtual environment, checking that your dependencies support the new version, running your tests with warnings turned into errors, and fixing removed or deprecated APIs before you switch production over. Treat an upgrade as a small project with a rollback path, not as a one-line change.
Python releases a new minor version every year in October, and each version gets about five years of security support. Moving one version at a time keeps each step small.
Before installing anything, collect the facts:
python --version, and check the supported versions in the official Python release schedule. Plan to move off any version that has reached end of life, because it no longer receives security fixes.python -m pip freeze or your lock file.Never replace the system Python that your operating system relies on. Install the new interpreter next to the old one and create a separate virtual environment.
On Windows, the py launcher selects a version, for example py -3.13 -m venv .venv-313, and the environment is activated with .venv-313\Scripts\activate. The built-in alternative is python3.13 -m venv .venv-313 on Linux and macOS.
Virtual environments cannot be upgraded in place across minor versions; delete and recreate them. Keep the old environment until the new one is verified.
Run the full test suite on the new interpreter, and turn deprecation warnings into failures so problems appear before the old behaviour is removed:
In pyproject.toml, you can make it permanent:
Common breakages when moving between recent versions:
| Area | What changed |
|---|---|
| Removed standard-library modules | Python 3.12 removed distutils and imp; Python 3.13 removed many legacy modules such as cgi, telnetlib and pipes (PEP 594) |
| Packaging | Use setuptools, build and pyproject.toml instead of distutils and setup.py install |
| Typing | New syntax such as type statements and generic class syntax arrived in 3.12; typing aliases like List are deprecated in favour of list |
| Compiled packages | NumPy, pandas and similar libraries need a release that supports the new version |
| Behaviour changes | Check "What's New" for changes to asyncio, datetime.utcnow() (deprecated in 3.12) and string handling |
Use a linter such as Ruff with the UP rules, or pyupgrade, to rewrite outdated syntax automatically.
When pip reports a conflict, read the message: it names the packages and the version ranges that cannot be satisfied together.
Practical rules:
pip-tools, uv.lock, Poetry or similar) so the environment is reproducible.python:3.12-slim to python:3.13-slim, and rebuild.Not across minor versions. Create a new virtual environment with the new interpreter and reinstall the dependencies.
Use the newest version that all your critical dependencies support. Many teams run the latest or the one before it, and always stay within the supported window.
Run python -m pip install -r requirements.txt in the new environment and read the first error. Then check the failing package's release notes for supported Python versions.
Usually because of removed APIs, stricter behaviour or a dependency that resolved to a different version. Compare pip freeze output between the two environments.
Install the new interpreter next to the old one, build a fresh virtual environment, and run the tests with deprecation warnings as errors. Resolve dependency conflicts with lock files and one change at a time, add the new version to CI, and keep the old build ready for rollback.