Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

python - How to use virtualenv with python3.6 on ubuntu 16.04?

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?

question from:https://stackoverflow.com/questions/47822740/how-to-use-virtualenv-with-python3-6-on-ubuntu-16-04

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...