Pip issue: No module named 'ensurepip'

ModuleNotFoundError: No module named 'ensurepip'

karchunt

Kar Chun Tan

Creator

Metadata

Sat May 17 2025

1 min read

190 words

Pip issue: No module named 'ensurepip'

When you create a virtual environment, you might encounter the following error:

Error: Command '['/home/kc/Desktop/projects/pretty/venv/bin/python3.11', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

The error indicates that the ensurepip module failed to set up pip in your virtual environment. This can happen if the Python installation is incomplete or corrupted, or if the virtual environment was not created properly.

Assuming you are using Python 3.11 on a Linux system, here are the steps to resolve this issue:

Ensure Python is Properly Installed

python3.11 --version
python3.11 -m ensurepip --version

If the above commands fail, reinstall Python 3.11

For your information, many Linux distributions disable the bundled ensurepip module to force use of system packaging. To fix this, you can reinstall Python along with the venv and dev packages.

If your system package name differs (eg, python3.11-venv), adjust accordingly.

sudo apt update
sudo apt install --reinstall python3.11 python3.11-venv python3.11-dev

Recreate the virtual environment

Now, delete the existing virtual environment and create a new one.

python3.11 -m venv venv