Interview Prep/Python for DevOps/Environments, dependencies & packaging

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.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, dependencies & packaging