Skip to main content
When creating a virtual environment in Python, you might encounter the following error:
python -m venv venv
Error: Command '['/home/ubuntu/venv/bin/python', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
This error typically occurs when the ensurepip module fails to install pip in the virtual environment.

Resolution

1
Check your Python version
2
python --version # e.g., 3.13.1
3
Install the venv package for your Python version
4
Replace 3.13 with your actual Python version:
5
sudo apt install python3.13-venv
6
Create the virtual environment
7
python3.13 -m venv myenv

Build docs developers (and LLMs) love