python venv: ensurepip is not available (tested)

The virtual environment was not created successfully because ensurepip is not available means your distro split venv's pip bootstrap into a separate package. We measured the error, what it leaves behind, and a fix that needs no sudo.

1. The exact error

python3 -m venv env1; echo "exit code: $?"
ls env1/bin

Output:

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

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

Failing command: /tmp/ve/env1/bin/python3

exit code: 1
python
python3
python3.13

Measured on Debian with Python 3.13.5: Debian and Ubuntu ship ensurepip in a separate package, so python3 -m venv fails with exit code 1. It still leaves a half-built env1 directory with a Python but no pip. Delete it (rm -rf env1) before you try again, or you'll end up with a venv with no pip that looks fine.

2. The normal fix (needs sudo)

Install the package the message names, for your exact Python version: sudo apt install python3.13-venv (or python3-venv), then delete the broken directory and run python3 -m venv again. We could not run this one on our test machine (no sudo), so it isn't measured here; it's the fix the error message itself gives.

3. Without sudo: --without-pip + get-pip.py

python3 -m venv --without-pip env2; echo "exit code: $?"
env2/bin/python -c "import sys; print(sys.prefix != sys.base_prefix)"
curl -sSL -o get-pip.py https://bootstrap.pypa.io/get-pip.py
env2/bin/python get-pip.py -q; echo "get-pip exit code: $?"
env2/bin/pip --version | cut -d' ' -f1-2

Output:

exit code: 0
True
get-pip exit code: 0
pip 26.2.1

Measured: --without-pip creates a working venv (exit code 0, sys.prefix differs from base_prefix), and the official get-pip.py bootstrap installs pip into it (pip 26.2.1 in our run). Read get-pip.py before running it if your policy requires it; it comes from the Python Packaging Authority.

4. Why not just pip install? externally-managed-environment

# ask the venv's pip to install into the system Python (--python, pip 22.3+)
env2/bin/pip --python /usr/bin/python3 install requests 2>&1 | head -4
echo ...
env2/bin/pip install -q requests; echo "pip install inside the venv: exit code $?"

Output:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
...
pip install inside the venv: exit code 0

Measured: installing into the system Python is refused with error: externally-managed-environment (PEP 668), because this Python has an EXTERNALLY-MANAGED marker file in /usr/lib/python3.13/. The same pip install inside the venv succeeds. That's the intended route: a venv for project packages, apt install python3-xyz for system ones. --break-system-packages overrides the check but can break tools your OS relies on.

Frequently asked questions

How do I fix 'ensurepip is not available' in python venv?

On Debian/Ubuntu install python3.X-venv (e.g. sudo apt install python3.13-venv), delete the half-created venv directory, and recreate it. We measured the error and the leftover directory on Python 3.13.5.

Can I create a venv without sudo when ensurepip is missing?

Yes: python3 -m venv --without-pip env, then run get-pip.py with the venv's python. We measured it installing pip 26.2.1.

What does error: externally-managed-environment mean?

Your OS marks its Python as managed by the package manager (PEP 668), so pip refuses system-wide installs. We measured the refusal and the same install succeeding inside a venv.

Why does my venv have no pip?

A failed python3 -m venv still leaves the directory behind with python but no pip. We measured exactly that; delete it and recreate.

Written with AI assistance. Measured on 2026-10-09 on Debian with Python 3.13.5: python3 -m venv failing without ensurepip, the half-created directory it leaves, --without-pip plus get-pip.py (pip 26.2.1), and externally-managed-environment against the system Python vs inside the venv. Every block was run verbatim and its output pasted from that run. The apt install fix was not run (no sudo on the test machine). PlainHeaders is our extension; Python, pip and get-pip.py are free.