Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

A new Python virtual environment on Ubuntu comes without pip

Your error

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.2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The python3-venv package is missing

Install python3-venv.

Fix
sudo apt update
sudo apt install python3-venv
rm -rf .venv
python3 -m venv .venv
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

On Ubuntu 24.04 and 26.04, python3 -m venv stops with 'ensurepip is not available' because the pip bootstrap ships in a separate apt package (python3.12-venv or python3.14-venv). Install python3-venv, delete the half-made folder and create it again. A venv made with uv venv or --without-pip has no pip either; add it with python -m ensurepip.

  • Applies to Ubuntu 24.04 LTS (Python 3.12.3, python3.12-venv), Ubuntu 26.04 LTS (python3-venv 3.14.3), uv 0.13.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Check two things: whether the ensurepip module exists on the system, and whether the venv folder holds a pip script. No ensurepip file means cause 1; ensurepip present but no pip in .venv/bin means cause 2; pip present in .venv/bin means cause 3.

Run this first
ls /usr/lib/python3*/ensurepip/__main__.py
ls .venv/bin/ | grep -i pip

Then find the line you see in this list and open its fix:

  1. 1The python3-venv package is missingpython3 -m venv prints the ensurepip message, and the ls of /usr/lib/python3*/ensurepip finds no file
  2. 2The venv was made by uv venv or with --without-pipCreating the venv printed no error, but .venv/bin holds python and the activate scripts and nothing named pip
  3. 3The pip being run is not the one inside the venvpip exists in .venv/bin, yet which pip prints /usr/bin/pip or nothing at all

What does the error look like?

  • 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.12-venv
  • ensurepip is disabled in Debian/Ubuntu for the system python.

Cause 1 of 3

The python3-venv package is missing

You seepython3 -m venv prints the ensurepip message, and the ls of /usr/lib/python3*/ensurepip finds no file

Check

The 'ensurepip is not available' message comes from Ubuntu's own patch to the venv module, which prints it when ensurepip/__main__.py is absent from the standard library. On Ubuntu 24.04 that file is part of python3.12-venv, and the same package depends on python3-pip-whl, the pip wheel that venv installs into each new environment.

Check
apt-cache policy python3-venv

Fix

Install python3-venv. It depends on the venv package for your release's default Python, so the same command works on 24.04 and 26.04. Then delete the folder left by the failed run and build it again, as the message itself asks.

Fix
sudo apt update
sudo apt install python3-venv
rm -rf .venv
python3 -m venv .venv

Verify

The new .venv/bin folder lists pip, and pip reports a path inside .venv.

Verify
.venv/bin/python -m pip --version

Confirmed by git.launchpad.net

Did this fix it?

Cause 2 of 3

The venv was made by uv venv or with --without-pip

You seeCreating the venv printed no error, but .venv/bin holds python and the activate scripts and nothing named pip

Check

An empty environment like this is expected, not broken. python3 -m venv --without-pip skips the pip bootstrap on purpose, and uv venv puts pip in only when you pass --seed. Ubuntu's ensurepip block applies to the system interpreter alone, so bootstrapping from inside the venv is allowed once python3-venv is installed.

Check
ls -l .venv/bin

Fix

Bootstrap pip with the venv's own interpreter. In a uv project, either recreate the venv with --seed or leave pip out and install packages through uv pip install.

Fix
.venv/bin/python -m ensurepip --upgrade

# uv alternatives
rm -rf .venv && uv venv --seed
uv pip install requests

Verify

pip now sits in .venv/bin and pip --version points into the venv.

Verify
.venv/bin/python -m pip --version

Confirmed by docs.python.org

Did this fix it?

Cause 3 of 3

The pip being run is not the one inside the venv

You seepip exists in .venv/bin, yet which pip prints /usr/bin/pip or nothing at all

Check

Activation is what puts .venv/bin at the front of PATH, so a bare pip command reaches the venv only in a shell where the activate script ran. A fresh terminal, a cron job or a systemd unit still finds the system pip first on PATH, or no pip at all, even though the venv is fine.

Check
which -a pip python3

Fix

Activate the venv in every new shell, or skip activation and call the venv's interpreter by its full path; the Python docs say that works the same way.

Fix
source .venv/bin/activate
python -m pip install requests

# no activation needed
.venv/bin/python -m pip install requests

Verify

After activation, which pip shows a path under .venv/bin.

Verify
which pip

Confirmed by docs.python.org

Did this fix it?

How do I stop it coming back?

  • List python3-venv beside python3 in the apt step of your server setup script or Dockerfile.
  • In scripts, cron jobs and systemd units, call .venv/bin/python -m pip rather than a bare pip.
  • When the team uses uv but some tools still expect pip in the venv, set UV_VENV_SEED=1 so uv venv always seeds it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.