Error when creating venv

Learn how to resolve the error when creating a virtual environment in Python.

karchunt

Kar Chun Tan

Creator

Metadata

Sat Apr 26 2025

1 min read

99 words

How to resolve the error when creating a virtual environment in Python

When creating a virtual environment in Python, you might encounter the following error:

python -m venv venv

# Error message:
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. Here are some steps to resolve this issue:

# Check python version
python --version # in this case, mine is 3.13.1
sudo apt install python3.13-venv # replace your version accordingly

python3.13 -m venv myenv