25

I want to create a venv having python3.8 as python3 On Ubuntu 18.04 I did:

> sudo apt install python3.8 python3.8-venv

Now, when I try:

> python3.8 -m venv env

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv   
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/home/pushp/vizio-backend/env/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']

My application depends on python3.8. What am I missing here?

Pushp Vashisht
  • 874
  • 3
  • 9
  • 17
  • Did you try `apt-get install python3-venv` like the error message said? The command you tried is a bit different. – Arthur Tacca Jul 07 '20 at 10:44
  • I did sudo apt purge python3.8-venv. Then, I did sudo apt install python3-venv and got the same error. – Pushp Vashisht Jul 07 '20 at 10:55
  • 1
    Possible duplicate of [pyvenv not working because ensurepip is not available](https://stackoverflow.com/questions/39539110/pyvenv-not-working-because-ensurepip-is-not-available) (procedural conversion of answer into close vote) – pppery Jul 07 '20 at 15:29
  • But `Python-3.8` is not in the default apt-repos of Ubuntu-1804("Bionic"); how did you installed it? To further research please 1) paste the contents of your `/etc/apt/sources.list(.d/)`, and 2) try to execute the `Failing command: ['/home/pushp/vizio-` from your shell and paste the edit the Q above to include the exception. – ankostis Jan 22 '21 at 16:17

5 Answers5

31

Resolved, what I did? :

apt install python3.8 python3.8-venv python3-venv

Dont know how but installing both the venv packages python3.8-venv python3-venv resolved it from me. Now when I do:

python3.8 -m venv env
source env/bin/activate
python3 --version
> Python 3.8.0
Pushp Vashisht
  • 874
  • 3
  • 9
  • 17
  • 4
    This did not work for me. python3-venv made no difference. – supermitch Sep 02 '20 at 19:15
  • 1
    I believe this may have "worked around" the problem ONLY because your host system also uses python3.x. `python3.8-venv` has a problem ... – some bits flipped Nov 03 '20 at 14:20
  • What is the source here in line #2, is this just a keyword? – Rashid Jul 26 '23 at 10:11
  • @Rashid The source command in line 2 is not a keyword. It is a shell command that tells the shell to execute the contents of the file specified after the source keyword. In this case, the file is env/bin/activate. This file is a shell script that sets up the environment variables needed to activate the virtual environment where all your local packages installed using pip are installed locally. – Pushp Vashisht Aug 08 '23 at 08:04
2

first: sudo pip3 install virtualenv then cd to the directory where you want your virtual environment to be: virtualenv "name of env" for ex: sudo virtualenv myProject-env then to activate: sudo source myProject-env/bin/activate to make sure that it is work: sudo which python

OMY
  • 402
  • 1
  • 8
  • 18
Kevin Omar
  • 127
  • 9
1

Installing python3-distutils also works around the problem.

Rob
  • 909
  • 1
  • 8
  • 14
0

You might miss the virtual environment installation in your machine.

You can install virtualenv using the following command,

sudo apt-get install python3.8-venv python3-venv

or

python3 -m pip install virtualenv
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81
-2

Referring this document from digitalOcean i got the same error but here in this linein this image change python3.6 to python3.8 then it will work fine. change python3.6 -m venv my_env to python3.8 -m venv my_env