Updated: 28 September 2026 · Applies to: Ubuntu 24.04 LTS (Python 3.12)
Ubuntu 18.04 is no longer supported. Ubuntu 24.04 includes Python 3.12, which is recent and fully supported.
Use the system Python with virtual environments
apt install python3 python3-venv python3-pip python3 -m venv ~/venvs/myproject source ~/venvs/myproject/bin/activate pip install --upgrade pip
Another Python version
The deadsnakes PPA provides other versions side by side:
add-apt-repository ppa:deadsnakes/ppa apt install python3.13 python3.13-venv python3.13 -m venv ~/venvs/py313
Note: Never replace or remove the system python3: Ubuntu's own tools depend on it. Tools such as uv or pyenv are alternatives for managing versions per project.
Why pip install fails with "externally-managed-environment"
Since Ubuntu 23.04, pip refuses to install packages into the system Python, so it cannot break system tools. Use one of these instead:
- A virtual environment for each project (shown above).
pipxfor command-line tools:apt install pipx && pipx install <tool>.- Ubuntu packages, if the library is packaged:
apt install python3-<name>.
Building Python from source
Only needed for a version that neither Ubuntu nor deadsnakes provides. Install the build dependencies, download the source from python.org, then:
./configure --enable-optimizations make -j"$(nproc)" make altinstall # never "make install": it would replace the system python3
Check the versions available with python3 --version and ls /usr/bin/python3*.