Solving Python pyvenv not working – The virtual environment was not created successfully because ensurepip is not available

Python pyvenv not working – The virtual environment was not created successfully because ensurepip is not available is an error which occurs when your virtualenv creation process is faulty.

In today’s blog post I am going to present an annoying and confusing python error and explain why this error is taking place and how to fix it, with a set of possible fixes.

Exploring Python pyvenv not working – The virtual environment was not created successfully because ensurepip is not available

This is an error which occurs when your virtual env creation process is faulty.

Please make sure the error message looks like the error message bellow after double checking. Do not mix between errors.

                                                                       #
The virtual environment was not created successfully because ensurepip is not
available.
                                                                       #

Bellow I will present multiple solutions some have worked for me and others have worked for other devs.

Solution 1 : update and upgrade before installing python3-venv

If you are running Ubuntu or Ubuntu on a Windows Linux Subsystem trying this method should be on the top of your priorities.

Before you install python3-venv you should upgrade first.

First, run the following command

                                                                       #
sudo apt update
                                                                       #

Followed by this command

                                                                       #
sudo apt install python3-venv
                                                                       #

If this does not work you can use the command bellow after using sudo apt update

                                                                       #
sudo apt upgrade
                                                                       #

If the error still persists you can replace python3-venv with python3.10-venv like in the next command

Make sure you respect all the steps above before doing that

                                                                       #
sudo apt install python3.10-venv
                                                                       #

If the whole process doe not fix your error, consider trying the method bellow.

Solution 2 : Correctly install setuptools and pip while installing python3.9-venv (or installing python3-venv)

Another thing that works for fixing this issue is installing setuptools and the pip package manager while installing python3.9-venv for example.

You can use one command to install everything

                                                                       #
apt install python3-setuptools python3-pip python3.9-venv
                                                                       #

If this does not work, please try this ( Basically replace python3.9-venv by python3-venv )

                                                                       #
apt install python3-setuptools python3-pip python3-venv
                                                                       #

Finally run the final command and see if the error still persists

                                                                       #
python3.9 -m venv /path/to/venv
                                                                       #

I hope the fixes above fixed your problem, good luck with your next python project, cheers.

Summing-up : 

Consider donating to my Kofi account if you want to support my efforts, thank you for reading and cheers.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/