TL;DR:
- Ubuntu 26.04 LTS ships Python 3.14 and has no
python3.12package, sosudo apt install python3.12stops withUnable to locate package python3.12. - Install it from the deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa, thensudo apt install python3.12 python3.12-venv. The PPA publishespython3.123.12.16 andpython3.133.13.18 for Ubuntu 26.04 (resolute). - Or install it for one user with uv 0.13.6:
uv python install 3.12installs Python 3.12.16 without sudo or an extra apt source. - Run pip inside a virtual environment. Outside one, pip on Ubuntu 26.04 stops with
error: externally-managed-environment(PEP 668). - Keep
/usr/bin/python3on 3.14. Pointed at 3.12,add-apt-repositoryandunattended-upgradefail withModuleNotFoundError: No module named 'apt_pkg'. - Python 3.12 receives security fixes only, until October 2028.
Applies to: Ubuntu 26.04 LTS · python3.12 3.12.16 (deadsnakes) · uv 0.13.6 · checked October 2026
Python 3.12 is a release of the Python programming language, first published on October 2, 2023, that receives source-only security fixes until October 2028. Ubuntu 26.04 LTS moved its system Python from 3.12 to 3.14, so an app pinned to 3.12 needs a second interpreter next to the system one. This tutorial shows how to install Python 3.12 on Ubuntu 26.04 from the deadsnakes PPA or with uv, create a virtual environment for one app, and fix error: externally-managed-environment.
Which Python version does Ubuntu 26.04 ship?
Ubuntu 26.04 LTS ships Python 3.14. The Ubuntu 26.04 summary for LTS users lists the update from 3.12 to 3.14, and python3.14 is the only python3.N interpreter package in the 26.04 archive.
| Python | Ubuntu 26.04 archive | deadsnakes PPA | uv 0.13.6 | python.org status | End of support |
|---|---|---|---|---|---|
| 3.12 | Not available | 3.12.16 | 3.12.16 | Security fixes only | October 2028 |
| 3.13 | Not available | 3.13.18 | 3.13.18 | Security fixes only | October 2029 |
| 3.14 | 3.14.4 (system Python) | Not built | 3.14.10 | Bug fixes | October 2030 |
| 3.15 | Not available | 3.15.2 | 3.15.2 | Bug fixes | October 2031 |
After 3.12.10, python.org publishes 3.12 releases as source code only. The deadsnakes PPA and uv ship prebuilt 3.12.16 binaries. pyenv and a source build compile Python on the server instead, which needs the Python build dependencies installed first.
A server upgraded with How to Upgrade Ubuntu 24.04 to 26.04 LTS on a VPS also runs 3.14 afterwards. If the upgrade removed python3.12, recreate the virtual environments built on it with one of the paths below.
deadsnakes or uv: which one to use
The deadsnakes PPA installs Python 3.12 for the whole server through apt. uv installs it in one user's home directory. Both leave the system python3 on 3.14.
| deadsnakes PPA | uv | |
|---|---|---|
| What it changes | Adds an apt source and installs /usr/bin/python3.12 | Adds uv and a Python build under ~/.local, with a python3.12 link in ~/.local/bin |
| Who can run Python 3.12 | Every user on the server | The user who installed it |
| Needs sudo | Yes | No |
| Patch updates | sudo apt upgrade | uv python upgrade 3.12 |
| Maintained by | The deadsnakes team on Launchpad, a community project | Astral, which builds CPython in its python-build-standalone project |
| pip outside a venv | Not blocked: with python3-pip installed, python3.12 -m pip installs into ~/.local | Blocked by uv's EXTERNALLY-MANAGED marker |
The PPA's description says there is "no guarantee of timely updates in case of security problems or other issues" and that anyone using it "on a production server" does so "at your own risk". Ubuntu's third-party repository guide states that PPAs lack official Ubuntu support. Choose deadsnakes when a systemd service or a script expects /usr/bin/python3.12. Choose uv for projects that one user runs, or for several Python versions side by side.
Prerequisites
- A server running Ubuntu 26.04 LTS. Arct Cloud offers Ubuntu 26.04 LTS as an Ubuntu VPS image.
- A non-root user with sudo privileges and SSH key login. How to Generate an SSH Key on Windows, macOS, and Linux covers creating the key and giving a sudo user access.
- About 30 MB of free disk space for each Python version from deadsnakes, or about 90 MB for each uv build.
Commands run as the sudo user, shown as deploy in sample output. Steps 1 to 4 use the deadsnakes PPA. To use uv instead, run Step 1, then continue at "Install Python 3.12 with uv instead".
Step 1: Check the system Python
Print the version of the system Python and list the interpreters in /usr/bin:
python3 --version
ls /usr/bin/python3*
The output looks similar to this:
Python 3.14.4
/usr/bin/python3
/usr/bin/python3.14
If python3 is not installed, run sudo apt update and then sudo apt install python3 to install 3.14 from the Ubuntu archive. If your app runs on Python 3.14, run sudo apt install python3-venv and create the environment as in Step 4 with python3 -m venv .venv. The rest of this tutorial adds Python 3.12 next to the system Python.
Update the package lists:
sudo apt update
Check whether apt can find Python 3.12:
apt-cache policy python3.12
apt-cache policy prints nothing, because the Ubuntu 26.04 archive has no package with that name. sudo apt install python3.12 fails at this point with Error: Unable to locate package python3.12.
Step 2: Add the deadsnakes PPA
The add-apt-repository command comes from the software-properties-common package. Install it:
sudo apt install software-properties-common
Type Y if apt asks to confirm. Add the PPA:
sudo add-apt-repository ppa:deadsnakes/ppa
The command prints the PPA's description, including the Ubuntu releases it builds for, then waits:
...
- Ubuntu 22.04 (jammy) Python3.7+ (NOT Python3.10)
- Ubuntu 24.04 (noble) Python3.7+ (NOT Python3.12)
- Ubuntu 26.04 (resolute) Python3.7+ (NOT Python3.14)
- Note: Python 3.10 (jammy), Python3.12 (noble), Python3.14 (resolute) are not provided by deadsnakes as upstream ubuntu provides those packages.
...
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
The (NOT Python3.12) entry applies to Ubuntu 24.04, which ships Python 3.12 itself. On Ubuntu 26.04 the PPA does not build Python 3.14. Press Enter. The command writes /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-resolute.sources with the PPA's signing key and refreshes the package lists. Confirm that apt now has a candidate:
apt-cache policy python3.12
The output looks similar to this:
python3.12:
Installed: (none)
Candidate: 3.12.16-1+resolute1
...
Step 3: Install python3.12 and python3.12-venv
Install the interpreter and its venv module. Without python3.12-venv, creating a virtual environment in Step 4 fails at the ensurepip step:
sudo apt install python3.12 python3.12-venv
The output looks similar to this:
Installing:
python3.12 python3.12-venv
Installing dependencies:
libpython3.12-stdlib
Suggested packages:
binutils
Summary:
Upgrading: 0, Installing: 3, Removing: 0, Not Upgrading: 0
Download size: 6832 kB
Space needed: 25.7 MB / 27.8 GB available
Type Y to confirm. Check both interpreters:
python3.12 --version
python3 --version
The output looks similar to this:
Python 3.12.16
Python 3.14.4
python3 still runs the system Python 3.14. Without the system python3-pip package, python3.12 -m pip prints No module named pip. With python3-pip installed, python3.12 -m pip runs Ubuntu's pip and installs packages into ~/.local/lib/python3.12, because the PPA build has no EXTERNALLY-MANAGED marker. The PPA's description says compiled modules from Ubuntu's python3-* packages do not work with its interpreters. Install your app's packages in a virtual environment.
Step 4: Create a virtual environment for your app
A virtual environment is a directory with its own Python interpreter link and its own set of installed packages. Create one in your app's directory with Python 3.12 and activate it:
mkdir -p ~/myapp
cd ~/myapp
python3.12 -m venv .venv
source .venv/bin/activate
Replace myapp with your app's directory. Check the interpreter and pip inside the environment:
python --version
pip --version
The output looks similar to this:
Python 3.12.16
pip 25.0.1 from /home/deploy/myapp/.venv/lib/python3.12/site-packages/pip (python 3.12)
Update pip, then install packages. This example installs requests:
pip install --upgrade pip
pip install requests
The output ends with a line similar to this:
Successfully installed certifi-2026.10.23 charset_normalizer-3.5.2 idna-3.20 requests-2.34.2 urllib3-2.8.0
For an app with a requirements file, run pip install -r requirements.txt. Run deactivate to leave the environment. A systemd service or cron job can run the environment's interpreter by its full path, such as /home/deploy/myapp/.venv/bin/python app.py, without activating it. Keep .venv out of Git and create it again on a new server instead of copying it, as Python's venv documentation advises.
Install Python 3.12 with uv instead
uv is a Python package and project manager from Astral, written in Rust, that also installs Python versions. Run its installer as your user, without sudo. If curl is not installed, run sudo apt install curl first:
curl -LsSf https://astral.sh/uv/install.sh | sh
To read the script first, replace | sh with | less. To pin the version checked here, use https://astral.sh/uv/0.13.6/install.sh. The output includes:
installing to /home/deploy/.local/bin
uv
uvx
everything's installed!
To add $HOME/.local/bin to your PATH, either restart your shell or run:
source $HOME/.local/bin/env (sh, bash, zsh)
source $HOME/.local/bin/env.fish (fish)
When ~/.local/bin is not on PATH yet, the installer adds a line that loads ~/.local/bin/env to ~/.bashrc and ~/.profile, creates ~/.zshrc with the same line if that file does not exist, and prints the hint above. Run the hint's source line to update PATH in the current shell:
source $HOME/.local/bin/env
If the output ends at everything's installed! with no hint, ~/.local/bin is already on PATH and the installer wrote no env file. Skip the source line. Install Python 3.12:
uv python install 3.12
The output includes:
Installed Python 3.12.16 in 2.20s
uv stores the build under ~/.local/share/uv/python and links it as ~/.local/bin/python3.12. Create a virtual environment with it:
mkdir -p ~/myapp
cd ~/myapp
uv venv --python 3.12
The output looks similar to this:
Using CPython 3.12.16
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate
A uv environment has no pip. Install packages with uv pip install, which uses the activated environment or the .venv in the current or a parent directory:
uv pip install requests
The output looks similar to this:
Resolved 5 packages in 885ms
Prepared 5 packages in 312ms
Installed 5 packages in 12ms
...
+ requests==2.34.2
+ urllib3==2.8.0
Activate the environment with source .venv/bin/activate, as in Step 4. uv python upgrade 3.12 moves the build to the newest 3.12 patch release, and environments created from it follow. uv self update updates uv itself.
Install Python 3.13 on Ubuntu 26.04
Python 3.13 installs the same way. With the deadsnakes PPA from Step 2:
sudo apt install python3.13 python3.13-venv
Type Y to confirm. Check the version:
python3.13 --version
The output looks similar to this:
Python 3.13.18
With uv, run uv python install 3.13, which installed Python 3.13.18. Create environments with python3.13 -m venv .venv or uv venv --python 3.13. Python 3.13 receives security fixes only, until October 2029.
The PPA also builds python3.11 3.11.18 for Ubuntu 26.04. Replace 3.12 with 3.11 in Steps 3 and 4 to install it. Python 3.11 receives security fixes until October 2027.
Why you should not set Python 3.12 as the default python3
Ubuntu's own tools run on /usr/bin/python3. add-apt-repository and unattended-upgrade, which installs automatic security upgrades, import apt_pkg from the python3-apt package, and that module is compiled for Python 3.14 only. In a throwaway container with /usr/bin/python3 pointed at 3.12 through update-alternatives, add-apt-repository stopped with:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 3, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
unattended-upgrade --dry-run failed with the same ModuleNotFoundError. With the command-not-found package installed, sudo apt update also ends with Error: Problem executing scripts APT::Update::Post-Invoke-Success, after a traceback from /usr/lib/cnf-update-db. Call Python 3.12 by its versioned name, python3.12, or use the interpreter inside a virtual environment.
If you already changed the link with update-alternatives, remove the alternative:
sudo update-alternatives --remove-all python3
Reinstall python3-minimal, which restores /usr/bin/python3. If you changed the link with ln -sf, this step alone restores it:
sudo apt install --reinstall python3-minimal
Check the version:
python3 --version
The output is Python 3.14.4 again.
Fix "error: externally-managed-environment"
pip prints this error when you install a package into the system Python 3.14 outside a virtual environment:
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
...
hint: See PEP 668 for the detailed specification.
PEP 668 lets a Linux distribution mark its Python with an EXTERNALLY-MANAGED file, and pip then refuses to install or remove packages there. Ubuntu 26.04 places the file at /usr/lib/python3.14/EXTERNALLY-MANAGED. Inside a virtual environment the check does not apply. Pick the fix that matches what you are installing:
| You want to | Run |
|---|---|
| Install packages for an app | Use a virtual environment: Step 4 for Python 3.12, or sudo apt install python3-venv and python3 -m venv .venv for Python 3.14 |
| Use a library that Ubuntu packages | sudo apt install python3-YOUR_PACKAGE, such as python3-requests |
| Install a command-line tool from PyPI | sudo apt install pipx, then pipx install YOUR_TOOL. pipx places the command in ~/.local/bin, so log in again if the command is not found |
The --break-system-packages flag skips the check, and pip's own message warns that it risks "breaking your Python installation or OS". uv marks its Python builds the same way, so pip outside a uv environment stops with This Python installation is managed by uv and should not be modified.
Remove Python 3.12 or the deadsnakes PPA
Remove every package you installed from the PPA. Leave out python3.13 and python3.13-venv if you did not install them:
sudo apt remove python3.12 python3.12-venv python3.13 python3.13-venv
Type Y to confirm. Remove the libraries apt installed with them, and type Y again:
sudo apt autoremove
Packages left installed from the PPA receive no further updates after you remove it. Remove the PPA itself and press Enter at the prompt:
sudo add-apt-repository --remove ppa:deadsnakes/ppa
Virtual environments created with the removed interpreter stop working, and .venv/bin/python reports No such file or directory. Delete them with rm -rf ~/myapp/.venv. To remove Python 3.12 that uv installed, run:
uv python uninstall 3.12
To remove uv as well, first delete the . "$HOME/.local/bin/env" line from ~/.bashrc and ~/.profile. Open each file with nano, such as nano ~/.bashrc, delete the line, save with Ctrl+O and exit with Ctrl+X. If the installer created ~/.zshrc and you do not use zsh, delete that file with rm ~/.zshrc; otherwise delete the same line from it. Then uninstall every Python uv manages and delete its data and binaries:
uv python uninstall --all
uv cache clean
rm -rf "$(uv python dir)" "$(uv tool dir)"
rm -f ~/.local/bin/uv ~/.local/bin/uvx ~/.local/bin/env ~/.local/bin/env.fish
rm -rf ~/.config/uv ~/.config/fish/conf.d/uv.env.fish
Troubleshoot common Python 3.12 errors
| Symptom | Cause | Fix |
|---|---|---|
Error: Unable to locate package python3.12 and Error: Couldn't find any package by glob 'python3.12' | Ubuntu 26.04 has no Python 3.12 package and the PPA is not added | Run Step 2, then install again |
sudo: 'add-apt-repository': command not found | software-properties-common is not installed | sudo apt install software-properties-common |
python3.12 -m venv ends with '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1 | python3.12-venv is not installed | sudo apt install python3.12-venv, then run the venv command again |
The virtual environment was not created successfully because ensurepip is not available | python3 -m venv without python3-venv | sudo apt install python3-venv |
/usr/bin/python3.12: No module named pip | python3-pip is not installed, and the PPA build ships no pip outside a virtual environment | Create a virtual environment (Step 4) and use its pip |
fatal error: Python.h: No such file or directory during pip install | The package builds a C extension and python3.12-dev is not installed | sudo apt install gcc python3.12-dev, then install again |
ModuleNotFoundError: No module named 'apt_pkg' from add-apt-repository or unattended-upgrade | /usr/bin/python3 points to Python 3.12 | sudo update-alternatives --remove-all python3, then sudo apt install --reinstall python3-minimal |
Error: Problem executing scripts APT::Update::Post-Invoke-Success after sudo apt update | /usr/bin/python3 points to Python 3.12, and cnf-update-db cannot import apt_pkg | Remove the alternative and reinstall python3-minimal, as in the row above |
python3.12: command not found after uv python install | ~/.local/bin is not on PATH in the current shell | source $HOME/.local/bin/env, or log in again |
error: No virtual environment found from uv pip install | No environment is activated and no .venv exists in the current or a parent directory | cd into the app directory, or run uv venv first |
Command 'python' not found, did you mean: or python: command not found | Ubuntu names the interpreter python3 | Use python3, activate a virtual environment, or install python-is-python3, which links python to python3 |
FAQ
How do I install Python 3.12 on Ubuntu 26.04?
Add the deadsnakes PPA with sudo add-apt-repository ppa:deadsnakes/ppa, then run sudo apt install python3.12 python3.12-venv, which installed Python 3.12.16 in October 2026. With uv, run uv python install 3.12. Python 3.12 receives security fixes until October 2028.
What Python version comes with Ubuntu 26.04?
Ubuntu 26.04 LTS comes with Python 3.14, and python3 --version printed Python 3.14.4 in October 2026. The 26.04 archive has no python3.12 or python3.13 package. This tutorial installs them from the deadsnakes PPA or with uv.
Does the deadsnakes PPA support Ubuntu 26.04?
Yes. The deadsnakes PPA has a resolute suite for Ubuntu 26.04, which listed python3.12 3.12.16 and python3.13 3.13.18 for amd64 and arm64 in October 2026. The "NOT Python3.12" line in its description refers to Ubuntu 24.04. On 26.04 it does not build Python 3.14, which Ubuntu ships.
Should I use uv or deadsnakes for Python 3.12?
Use deadsnakes when services or scripts for every user expect /usr/bin/python3.12. Use uv for projects that one user runs, with no sudo and no extra apt source. Both leave the system python3 on 3.14.
How do I fix error: externally-managed-environment?
Install the package inside a virtual environment: run sudo apt install python3-venv, then python3 -m venv .venv, source .venv/bin/activate and pip install. For a library Ubuntu packages, run sudo apt install python3-YOUR_PACKAGE. pip warns that --break-system-packages risks breaking your Python installation or OS.
Can I change the default python3 on Ubuntu 26.04?
Leave /usr/bin/python3 on Python 3.14. add-apt-repository and unattended-upgrade import a module built for 3.14 and fail on 3.12 with No module named 'apt_pkg'. Run python3.12 by name or activate a virtual environment instead.
How do I install Python 3.13 on Ubuntu 26.04?
Add the deadsnakes PPA and run sudo apt install python3.13 python3.13-venv, which installed Python 3.13.18 in October 2026. With uv, run uv python install 3.13. Python 3.13 receives security fixes only, until October 2029.
Next steps
- How to Install Docker and Docker Compose on Ubuntu 24.04 and 26.04, to run a Python app in a container that carries its own interpreter
- How to Install Hermes Agent on Ubuntu 26.04 and Keep It Running. Its installer downloads uv and a pinned Python 3.14 itself, so it needs neither path above.
- uv documentation: Installing Python
- Python documentation: venv
Arct Cloud Linux images, including Ubuntu 26.04 LTS, deploy in under 30 seconds on every plan. Compare plans.
This work is licensed under CC BY-NC-SA 4.0.