Skip to main content
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.
This 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.
Many Linux distributions disable the bundled ensurepip module to force use of system packaging. The steps below resolve this for Python 3.11 on Linux — adjust the version as needed.

Resolution

1
Ensure Python is properly installed
2
python3.11 --version
python3.11 -m ensurepip --version
3
Reinstall Python with venv and dev packages
4
If the commands above fail, reinstall Python along with the venv and dev packages:
5
sudo apt update
sudo apt install --reinstall python3.11 python3.11-venv python3.11-dev
6
If your system package name differs (e.g., python3.11-venv), adjust the package name accordingly.
7
Recreate the virtual environment
8
Delete the existing virtual environment and create a new one:
9
python3.11 -m venv venv

Build docs developers (and LLMs) love