如何在Ubuntu 16.04上将virtualenv与python3.6一起使用? [英] How to use virtualenv with python3.6 on ubuntu 16.04?
问题描述
我正在使用Ubuntu 16.04,该版本随附Python 2.7和Python 3.5.我已经在上面安装了Python 3.6,并通过alias python3=python3.6
将python3符号链接到python3.6.
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
.
然后,我使用sudo -H pip3 install virtualenv
安装了virtualenv
.当我检查时,virtualenv安装在"/usr/local/lib/python3.5/dist-packages"
位置,因此,当我尝试使用python3 -m venv ./venv1
创建virtualenv时,会抛出错误:
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']
我该怎么办?
推荐答案
我们通常使用$ python3 -m venv myvenv
创建一个新的virtualenv(此处myvenv
是我们的virtualenv的名称).
We usually use $ python3 -m venv myvenv
to create a new virtualenv (Here myvenv
is the name of our virtualenv).
类似于我的情况,如果您的系统上同时有python3.5
和python3.6
,那么您可能会遇到一些错误.
Similar to my case, if you have both python3.5
as well as python3.6
on your system, then you might get some errors.
注意::在某些版本的Debian/Ubuntu中,您可能会收到以下错误消息:
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.
在这种情况下,请按照上述说明安装python3-venv软件包:
In this case, follow the instructions above and install the python3-venv package:
$ sudo apt-get install python3-venv
注意::在某些版本的Debian/Ubuntu上启动这样的虚拟环境当前会产生以下错误:
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']
要解决此问题,请改用virtualenv命令.
To get around this, use the virtualenv command instead.
$ sudo apt-get install python-virtualenv
$ virtualenv --python=python3.6 myvenv
注意::如果出现类似错误
E:无法找到软件包python3-venv
E: Unable to locate package python3-venv
然后运行:
sudo apt install python3.6-venv
这篇关于如何在Ubuntu 16.04上将virtualenv与python3.6一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!