Skip to content
Nilay Kabariya

Entry No.115·Fixes··2 min read

Fix: "ensurepip is not available" (python3 -m venv)

python3 -m venv fails on Debian and Ubuntu until one apt package is in. Tested on Ubuntu 22.04 to 26.04 and Debian 12 and 13, plus the deadsnakes case.

by Nilay#python#ubuntu#debianFIXED

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 .venv
Not 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

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 .venv

You 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

Useful? Pass it on:Post on XFollow @EmotionalMatter

Related entries

  1. No.074

    pip error: externally-managed-environment, tested on 8 systems

    Ubuntu 24.04+, Debian 12+ and Homebrew Python block pip install; Ubuntu 22.04, Fedora and Docker python images don't. Which fix to use: venv, uv, pipx or apt.

    > error: externally-managed-environment

    FIXED4 min
  2. No.100

    Fix: Puppeteer "Failed to launch the browser process" (Code: 127)

    Chrome downloads, then Puppeteer exits with Code: 127 on slim Debian. The missing libraries, apt packages for Debian 12 and 13, and the launch that worked.

    > Error: Failed to launch the browser process: Code: 127

    FIXED2 min
  3. No.094

    Python CERTIFICATE_VERIFY_FAILED, tested on 3.12 to 3.15

    certificate verify failed: unable to get local issuer certificate, or Basic Constraints of CA cert not marked critical on Python 3.13+. Each cause tested.

    > requests.exceptions.SSLError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/

    FIXED3 minWindows
  4. No.083

    ModuleNotFoundError: No module named X, but it's installed

    pip installed it into one Python and your code runs another: a venv not activated, a Jupyter kernel, a second Python. Five cases reproduced, and the check.

    > Traceback (most recent call last):

    FIXED3 min

tip: paste the exact error text