如何在 ubuntu 16.04 上使用 virtualenv 和 python3.6?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47822740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use virtualenv with python3.6 on ubuntu 16.04?
提问by wgetDJ
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
.
我使用的是 Ubuntu 16.04,它带有 Python 2.7 和 Python 3.5。我已经在其上安装了 Python 3.6 并将 python3 符号链接到 python3.6 到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:
然后,我已经virtualenv
使用sudo -H pip3 install virtualenv
. 当我检查时,virtualenv 安装在"/usr/local/lib/python3.5/dist-packages"
位置,所以当我尝试使用python3 -m venv ./venv1
它创建 virtualenv 时,它会抛出错误:
Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
What should I do?
我该怎么办?
回答by wgetDJ
We usually use $ python3 -m venv myvenv
to create a new virtualenv (Here myvenv
is the name of our virtualenv).
我们通常$ python3 -m venv myvenv
用来创建一个新的virtualenv(这里myvenv
是我们的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.
与我的情况类似,如果您的系统同时python3.5
拥有 和python3.6
,那么您可能会遇到一些错误。
NOTE:On some versions of Debian/Ubuntu you may receive the following error:
注意:在某些版本的 Debian/Ubuntu 上,您可能会收到以下错误:
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:
在这种情况下,请按照上面的说明安装 python3-venv 包:
$ sudo apt-get install python3-venv
NOTE:On some versions of Debian/Ubuntu initiating the virtual environment like this currently gives the following error:
注意:在某些版本的 Debian/Ubuntu 上,像这样启动虚拟环境当前会出现以下错误:
Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
To get around this, use the virtualenv command instead.
要解决此问题,请改用 virtualenv 命令。
$ 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
E: 无法定位包 python3-venv
then instead run:
然后运行:
sudo apt install python3.6-venv
回答by Orny
Installing python3.6
and python3.6-venv
via ppa:deadsnakes/ppa
instead of ppa:jonathonf/python-3.6
worked for me
安装python3.6
和python3.6-venv
通过ppa:deadsnakes/ppa
而不是ppa:jonathonf/python-3.6
为我工作
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
回答by cryptoKTM
First make sure you have python3.6 installed, otherwise you can install it with command:
首先确保你已经安装了python3.6,否则你可以使用命令安装它:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.6
Now install venv i.e
现在安装 venv 即
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
您可以使用上面的命令安装python3.7/3.8以及相应的venv,只需将3.6替换为3.X
回答by Zen
I think that a problem could be related to the wrong locale.
I added to the /etc/environment
the following lines to fix it:
我认为问题可能与错误的语言环境有关。我添加/etc/environment
了以下几行来修复它:
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
You need to source the file from you bash with this command:
您需要使用以下命令从 bash 中获取文件:
source /etc/environment