47

I'm using Ubuntu 16.04, which comes with Python 2.7 and Python 3.5. I've installed Python 3.6 on it and symlink python3 to python3.6 through alias python3=python3.6.

Then, I've installed virtualenv using sudo -H pip3 install virtualenv. When I checked, the virtualenv got installed in "/usr/local/lib/python3.5/dist-packages" location, so when I'm trying to create virtualenv using python3 -m venv ./venv1 it's throwing me errors:

Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

What should I do?

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
wgetDJ
  • 1,209
  • 1
  • 10
  • 11

5 Answers5

60

We usually use $ python3 -m venv myvenv to create a new virtualenv (Here myvenv is the name of our virtualenv).

Similar to my case, if you have both python3.5 as well as python3.6 on your system, then you might get some errors.

NOTE: On some versions of Debian/Ubuntu you may receive the following error:

 The virtual environment was not created successfully because ensure pip is not available.  On Debian/Ubuntu systems, you need to install the python3-venv package using the following command.
      apt-get installpython3-venv  
 You may need to use sudo with that command.  After installing the python3-venv package, recreate your virtual environment. 

In this case, follow the instructions above and install the python3-venv package:

$ sudo apt-get install python3-venv

NOTE: On some versions of Debian/Ubuntu initiating the virtual environment like this currently gives the following error:

Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

To get around this, use the virtualenv command instead.

$ sudo apt-get install python-virtualenv
$ virtualenv --python=python3.6 myvenv

NOTE: If you get an error like

E: Unable to locate package python3-venv

then instead run:

sudo apt install python3.6-venv
wgetDJ
  • 1,209
  • 1
  • 10
  • 11
  • Very thorough answer but even more errors result from 'sudo apt install python3.6-venv' so I got lazy and went with Orny's answer which seemed to work. – shermy Aug 31 '18 at 08:34
  • 1
    E: Unable to locate package python3.6-venv E: Couldn't find any package by glob 'python3.6-venv' E: Couldn't find any package by regex 'python3.6-venv' – Coffee inTime Apr 12 '20 at 19:54
22

Installing python3.6 and python3.6-venv via ppa:deadsnakes/ppa instead of ppa:jonathonf/python-3.6 worked for me

apt-get update \
&& apt-get install -y software-properties-common curl \
&& add-apt-repository ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y python3.6 python3.6-venv
Orny
  • 665
  • 6
  • 16
  • 3
    This worked for me. Seems like some error was introduced recently in the jonathonf repository. I needed to downgrade to standard packages first, see https://askubuntu.com/a/899668/320633. – Jonas Dahlbæk May 15 '18 at 10:21
19

Ubuntu

First make sure you have python3.6 installed, otherwise you can install it with command:

sudo add-apt-repository ppa:deadsnakes/ppa   
sudo apt-get update   
sudo apt install python3.6

Now install venv i.e

sudo apt-get install python3.6-venv python3.6-dev
python3.6 -m venv venv_name

You can install python3.7/3.8 and also respective venv with above comman, just replace 3.6 with 3.X

For Mac users python3 -m venv venv_name

cryptoKTM
  • 2,593
  • 22
  • 21
2

I think that a problem could be related to the wrong locale. I added to the /etc/environment the following lines to fix it:

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

You need to source the file from you bash with this command:

source /etc/environment
Zen
  • 917
  • 1
  • 7
  • 20
  • Nothing works for me. I have tried every solution but none has worked. What version of Ubuntu has the bug been solved, so that I simply install it and uninstall what I have? – chibole Sep 20 '18 at 21:10
1

if you get following irritating error:

E: Unable to locate package python3-venv

try this commands:

sudo apt-get update

sudo apt-get install software-properties-common

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt-get update

sudo apt-get install python3.6

those worked for me.hope it helps !