SoFunction
Updated on 2025-03-03

Python venv creation problem

In Ubuntu, the author fails when he needs to create a virtual environment:

python3.11 -m venv env

The error message is as follows:

Error: Command '['****/env/bin/python3.11', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

Try to execute it to see what the error is:

python3.11 -m ensurepip --upgrade --default-pip

The specific information is as follows:

/usr/bin/python3.11: No module named ensurepip

Solution

Search for information online and determine that ubtuntu has no full version installed by default, and can be solved by installing the full version on the official website.

However, because the author has many Python environments (different versions) and are installed through apt, the following solution is adopted:

Install the venv library:

sudo apt install python3.11-venv

At this point, the virtual environment is recreated and the author's problem is solved. For more related Python venv creation, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!