Guides

How to install Python on Ubuntu and Debian: python3, venv, pip and newer versions

Install Python on Ubuntu or Debian: which python3 each release ships, apt install python3-venv python3-pip, virtual environments and newer versions.

Published ~8 min read
On this page

Short answer: Ubuntu already ships Python 3: version 3.12 on 24.04, 3.10 on 22.04 and 3.14 on 26.04. To get it complete with venv and pip, run sudo apt install python3 python3-venv python3-pip, then install packages inside a virtual environment. Need a newer Python? Add it next to the system one, and never replace /usr/bin/python3.

Ubuntu · Debian
sudo apt update
sudo apt install -y python3 python3-venv python3-pip
python3 --version

# packages go into a virtual environment, not into the system
python3 -m venv ~/venvs/myapp
source ~/venvs/myapp/bin/activate
pip install requests

Run on Debian 12 on 21 October 2026: python3 --version printed Python 3.11.2, and the venv error and the EXTERNALLY-MANAGED text quoted below come from that machine. The Ubuntu versions are taken from the Ubuntu archive on Launchpad and the Debian ones from packages.debian.org, as of October 2026. Debian uses the same package names, so every apt command here works on both.

Which Python version does each Ubuntu and Debian release ship?

Releasepython3Upstream end of life of that version
Ubuntu 26.04 LTS3.14October 2030
Ubuntu 24.04 LTS3.12October 2028
Ubuntu 22.04 LTS3.10October 2026
Debian 13 (trixie)3.13October 2029
Debian 12 (bookworm)3.11October 2027

The end-of-life column is python.org’s schedule from the Python developer’s guide. It does not decide whether your python3 gets security fixes: Ubuntu and Debian keep patching the version they shipped for as long as the release itself is supported, which is why 3.10 on 22.04 is still a sound choice for software that runs on it. What a release never does is move to a new minor version. Ubuntu 24.04 stays on 3.12 for its whole life, and apt upgrade only brings patch releases of it. The newest Python, 3.15, came out on 9 October 2026; no Ubuntu LTS ships it. Checking the Python version covers every way to see what you have, including inside a script.

How do I install Python 3 on Ubuntu or Debian?

  1. 1See what is already there
    Debian 12 · run 21.10.2026
    $ python3 --version
    Python 3.11.2

    Ubuntu Server and the usual cloud images include python3, because parts of the system are written in it. A minimal Debian or a container image may not, and then the shell answers python3: command not found.

  2. 2Install the interpreter, venv and pip
    Ubuntu · Debian
    sudo apt update
    sudo apt install -y python3 python3-venv python3-pip

    Debian and Ubuntu split Python into several packages. python3-venv is the one people miss: without it, python3 -m venv cannot put pip into a new environment. python3-full pulls in the whole standard set at once, including venv and the IDLE editor, if you would rather not pick.

  3. 3Add build tools if a package compiles C code
    Ubuntu · Debian
    sudo apt install -y python3-dev build-essential

    Most packages on PyPI ship ready-built wheels. The ones that do not, or a wheel missing for your Python version, need the headers in python3-dev and a compiler.

  4. 4Optional: make python mean python3
    Ubuntu · Debian
    sudo apt install -y python-is-python3

    Ubuntu and Debian install no python command, only python3, so old scripts and tutorials fail with python: command not found. This package is little more than the /usr/bin/python and /usr/bin/pydoc links to their Python 3 counterparts, kept up to date by apt. python: command not found covers the other causes, such as a shebang line that names python.

Skip python3-venv and the first virtual environment fails like this (Debian 12, path shortened):

Debian 12 · python3-venv not installed
$ python3 -m venv .venv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.11-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: /srv/app/.venv/bin/python3

Take the “recreate” literally: the failed attempt leaves a half-built .venv directory behind (in the Debian 12 run above it had bin, lib and pyvenv.cfg, but no pip and no activate script). Delete it with rm -rf .venv after installing the package, then create it again.

Why pip install fails: virtual environments and PEP 668

On Ubuntu 23.04 and later and on Debian 12 and later, pip install outside a virtual environment stops with error: externally-managed-environment. That is PEP 668 at work: the distribution puts a marker file next to the standard library to tell pip that apt owns this Python. On Debian 12 it is /usr/lib/python3.11/EXTERNALLY-MANAGED, and its message is the advice you should follow:

Debian 12 · /usr/lib/python3.11/EXTERNALLY-MANAGED, shortened
To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.

A virtual environment is a directory with its own site-packages and its own pip, linked to the system interpreter. Packages you install there cannot break apt or the tools the system runs on Python:

any Linux
python3 -m venv ~/venvs/myapp          # create it once
source ~/venvs/myapp/bin/activate       # python and pip now mean the venv's
pip install -r requirements.txt
deactivate

~/venvs/myapp/bin/python app.py         # scripts and services: call the venv's python directly
  • Libraries for your own code: a venv per project.
  • Command-line tools from PyPI: sudo apt install pipx, then pipx install NAME. pipx gives each tool its own hidden venv and puts the command on your PATH.
  • A library the system already packages: sudo apt install python3-NAME, such as python3-requests.

pip offers --break-system-packages to override the block. The name is accurate; leave it alone. The pip guide covers pip itself, requirements files and the rest of its error messages.

How do I install a newer Python version on Ubuntu?

Install it next to the system Python and call it by its versioned name or through a venv. Four ways, from least to most work:

MethodWorks onWhere it installsUpdates
deadsnakes PPAUbuntu LTS only/usr/bin/python3.XWith apt upgrade, from volunteers
uvAny Linux~/.local/share/uv/pythonuv python install again
pyenvAny Linux~/.pyenv/versionsYou rebuild it
Build from sourceAny Linux/usr/local/bin/python3.XYou rebuild it

deadsnakes PPA (Ubuntu)

deadsnakes is a community PPA, run by volunteers rather than by Canonical, that builds newer and older Pythons as normal Ubuntu packages. As of October 2026 it publishes for 22.04, 24.04 and 26.04, and never the version a release already ships (no 3.12 for 24.04, for example). Its own description warns that there is “no guarantee of timely updates in case of security problems”, so weigh that for anything facing the internet.

Ubuntu 22.04 · 24.04
sudo apt install -y software-properties-common     # provides add-apt-repository
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.14 python3.14-venv
python3.14 -m venv .venv

Install the matching -venv package, or the venv fails exactly as shown above. Do not add the PPA on Debian: it is built against Ubuntu’s libraries. If add-apt-repository itself is missing, see add-apt-repository: command not found.

uv-managed Pythons (any distribution)

any Linux, as your user
curl -LsSf https://astral.sh/uv/install.sh | sh   # installs uv into ~/.local/bin
uv python install 3.14
uv venv --python 3.14 .venv
source .venv/bin/activate
uv pip install requests

uv downloads a prebuilt interpreter from the python-build-standalone project instead of compiling one, so this takes seconds and needs no sudo. Its environments contain no pip unless you create them with --seed; use uv pip install inside them.

pyenv (any distribution)

Ubuntu · Debian
sudo apt install -y make build-essential libssl-dev zlib1g-dev \
  libbz2-dev libreadline-dev libsqlite3-dev curl git \
  libncurses-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev libzstd-dev
curl -fsSL https://pyenv.run | bash
# add the PYENV_ROOT, PATH and "pyenv init" lines the installer prints to ~/.bashrc, open a new shell
pyenv install 3.14          # the latest 3.14.x
pyenv local 3.14            # this directory now uses it

pyenv compiles Python on your server, which takes a few minutes and needs every library above. Skip one and the build still finishes, but the module is missing later: No module named '_ssl' or _ctypes means install the -dev package and run pyenv install again.

Building from source

If you compile a python.org tarball yourself, finish with sudo make altinstall, never make install. The Python documentation warns that make install “can overwrite or masquerade the python3 binary”: it creates /usr/local/bin/python3, which comes before /usr/bin in PATH and quietly takes over every command and script that finds python3 through PATH. altinstall installs only python3.14 and leaves python3 alone.

Never replace /usr/bin/python3

The system Python is not only for you. On the Debian 12 machine this page was checked on, 43 programs in /usr/bin and /usr/sbin start with a python3 shebang, among them cloud-init and apt-listchanges. They import modules installed for exactly the version the release ships. Point /usr/bin/python3 at another version, with ln -sf or update-alternatives, and those tools fail. The classic symptom on Ubuntu is ModuleNotFoundError: No module named 'apt_pkg' from add-apt-repository or an apt hook.

Common errors when installing Python on Ubuntu

MessageCauseFix
python3: command not foundMinimal image without Pythonsudo apt install python3
python: command not foundOnly python3 existssudo apt install python-is-python3
ensurepip is not availablepython3-venv missingInstall python3-venv (or python3.X-venv), delete the half-built venv, create it again
error: externally-managed-environmentpip outside a venv (PEP 668)Use a venv, pipx, or the python3-NAME apt package
E: Unable to locate package python3.14PPA not added, or you are on DebianAdd deadsnakes on Ubuntu; use uv or pyenv on Debian. See Unable to locate package
No module named 'apt_pkg'/usr/bin/python3 points at another versionRestore the link (see above)
No module named '_ssl'pyenv build without libssl-devInstall the build dependencies, run pyenv install again

On Windows none of these commands apply: install Python with the installer from python.org, then check it as shown in the version guide linked above.

Python on an Ubuntu server

For an app that runs permanently, create its venv in the app directory and point the service straight at it, for example ExecStart=/srv/app/.venv/bin/python app.py in a systemd unit; no activation needed. Plan for one chore: a release upgrade, say 22.04 to 24.04, replaces Python 3.10 with 3.12, and venvs built on the old interpreter stop working. Recreate them from requirements.txt after the upgrade, which takes a minute when the requirements file is up to date.

Our Ubuntu VPS starts from an Ubuntu 24.04 or 22.04 template with full root, so everything above works as written; run python3 --version after the first login to see where you start. Take a snapshot in the panel before you experiment with PPAs or a source build.

Frequently asked

Which Python version comes with Ubuntu?

Ubuntu 26.04 LTS ships Python 3.14, 24.04 LTS ships 3.12 and 22.04 LTS ships 3.10. Debian 13 ships 3.13 and Debian 12 ships 3.11. A release keeps its minor version for its whole life; apt only brings patch updates of it.

How do I install pip and venv on Ubuntu?

Run sudo apt install python3-venv python3-pip. Then create a virtual environment with python3 -m venv ~/venvs/myapp, activate it with source ~/venvs/myapp/bin/activate and install packages with pip inside it. pip outside a virtual environment stops with externally-managed-environment on Ubuntu 23.04 and later and on Debian 12 and later.

How do I install a newer Python version on Ubuntu?

Install it next to the system Python: from the community-run deadsnakes PPA on Ubuntu (sudo add-apt-repository ppa:deadsnakes/ppa, then sudo apt install python3.14 python3.14-venv), or with uv python install 3.14 or pyenv on any distribution. Call it as python3.14 or through a virtual environment, and never point /usr/bin/python3 at it.

Can I change the default python3 on Ubuntu?

No. apt hooks, cloud-init and other system tools run on /usr/bin/python3 and import modules built for the release's own version, so switching it breaks them, often with No module named 'apt_pkg'. Use a virtual environment built from the newer Python instead.

Related articles

All guides