How do you manage multiple Python versions on one machine?
IntermediateConceptEnvironments, dependencies & packaging
Answer
Do not replace the OS python3. Install additional versions side by side using pyenv, uv python install 3.12, the deadsnakes PPA on Ubuntu, or official installers, then create venvs from the version you need: python3.12 -m venv .venv or uv venv --python 3.12. Pin the version in .python-version and in requires-python. In Docker, the base image tag (python:3.12-slim) is the version pin.
More on Environments, dependencies & packaging
What is a virtual environment and why do we always use one?BeginnerWhat does `error: externally-managed-environment` mean?Beginner`requirements.txt` vs `pyproject.toml`: what goes where?IntermediateWhy is `pip freeze > requirements.txt` not a great lock strategy?IntermediateWhat do version specifiers like `~=`, `==`, `>=,<` mean?BeginnerWhat are `pipx` and `uv`, and when do you use them?Intermediate