且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Ubuntu 16.04上将virtualenv与python3.6一起使用?

更新时间:2023-10-06 10:05:58

我们通常使用$ 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.5python3.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