Pip issue: No module named 'ensurepip'

ModuleNotFoundError: 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.

Ensure Python is Properly Installed

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

If the above commands fail, reinstall Python 3.11

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

Recreate the virtual environment

python3.11 -m venv venv

Written by

KarChunT

Last Updated

Sat May 17 2025

Tags

Python