The error, verbatim
Jump to the fix ↓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
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: /home/me/app/.venv/bin/python3
The fix that worked
Install the venv package, then run the same command again:
sudo apt install python3-venv
python3 -m venv .venvNot it? Every cause, tested ↓Tested on
- Ubuntu
- 22.04.5, 24.04.5, 26.04.1 (Docker images)
- Debian
- 12 (bookworm), 13 (trixie)
- Python
- 3.10.12, 3.11.2, 3.12.3, 3.13.5, 3.14.4 (each distro's own); 3.13.18 from deadsnakes
- Where
- GitHub Actions, November 10, 2026
✓ Last re-run on GitHub Actions · see the run · all repros
Contents
On Debian and Ubuntu, python3 from apt comes without the part that installs pip into a new virtual environment. Debian moves it into a separate package, python3.X-venv. Until that package is installed, python3 -m venv stops with this message. It happened on every release I tried, from Ubuntu 22.04 to 26.04 and on Debian 12 and 13.
The fix
Install the venv package, then create the environment again:
sudo apt install python3-venv
python3 -m venv .venvYou don’t have to delete the half-made .venv first. Running the same command over it after the install worked on all five, and the pip inside was the same version as in a fresh one.
Which package the message names
The message asks for the package that matches your Python version. python3-venv points to the right one on each release, so it’s the safe name to type:
| Release | Python | Message says | python3-venv installed |
|---|---|---|---|
| Ubuntu 22.04.5 | 3.10.12 | apt install python3.10-venv |
python3.10-venv |
| Ubuntu 24.04.5 | 3.12.3 | apt install python3.12-venv |
python3.12-venv |
| Ubuntu 26.04.1 | 3.14.4 | apt install python3.14-venv |
python3.14-venv |
| Debian 12 | 3.11.2 | apt install python3.11-venv |
python3.11-venv |
| Debian 13 | 3.13.5 | apt install python3.13-venv |
python3.13-venv |
What the failed command leaves behind
The failed python3 -m venv .venv still creates the .venv folder, with python and python3 in .venv/bin, but no pip and no activate script, so there is nothing to activate. In my test containers, which had no system pip, pip wasn’t found at all after that. If your machine has the system pip and pip install then says externally-managed-environment, the venv didn’t get created: fix it first.
Python from deadsnakes: a different message
On Ubuntu 22.04 with Python 3.13 from the deadsnakes PPA, python3-venv was already installed, and python3 -m venv (the system 3.10) worked. python3.13 -m venv still failed, with a shorter message that doesn’t mention the package:
Error: Command '['/tmp/d/b/bin/python3.13', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
python3-venv only covers the distro’s own Python. Each extra version needs its own package:
sudo apt install python3.13-venv
If you can’t install packages
Test setup
Clean ubuntu:22.04, ubuntu:24.04, ubuntu:26.04, debian:12 and debian:13 containers on a GitHub Actions ubuntu-latest runner, November 10, 2026, running as root. Each installed only python3 from apt (plus curl and ca-certificates for uv), then ran the steps above in order. The deadsnakes case used ubuntu:22.04 with python3, python3-venv and python3.13 from ppa:deadsnakes/ppa. Run 42825326625, scripts.
— N.K., end of entry No.115