无法使用 python 3.6 创建虚拟环境

Nik*_*eev 11 python virtualenv

我在 Ubuntu 17.04 上安装了 python 3.6。现在,我正在尝试使用命令创建虚拟环境:

python3.6 -m venv env
Run Code Online (Sandbox Code Playgroud)

但我收到以下消息:

The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt-get install python3-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/home/makeev/test2/l/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']
Run Code Online (Sandbox Code Playgroud)

sudo apt install python3-venv 没有帮助,我安装了这个包。

Fat*_*lin 10

由于您专门安装python3.6而不是 Ubuntu 的默认 python3 版本,即python3.5,您必须安装python3.6-venv而不是,python3-venv因为这将解析为python3.5-venv.

为此,您可以使用sudo apt install python3.6-venv.


wge*_*tdj 5

我们通常$ python3 -m venv myvenv用来创建一个新的virtualenv(这里myvenv是我们的virtualenv 的名字)。

与我的情况类似,如果您的系统同时python3.5拥有 和python3.6,那么您可能会遇到一些错误。

注意:在某些版本的 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. 
Run Code Online (Sandbox Code Playgroud)

在这种情况下,请按照上面的说明安装 python3-venv 包:

$ sudo apt-get install python3-venv
Run Code Online (Sandbox Code Playgroud)

注意:在某些版本的 Debian/Ubuntu 上,像这样启动虚拟环境当前会出现以下错误:

Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
Run Code Online (Sandbox Code Playgroud)

要解决此问题,请改用 virtualenv 命令。

$ sudo apt-get install python-virtualenv
$ virtualenv --python=python3.6 myvenv
Run Code Online (Sandbox Code Playgroud)

注意:如果您收到类似的错误

E: 无法定位包 python3-venv

然后运行:

sudo apt install python3.6-venv
Run Code Online (Sandbox Code Playgroud)