无法使用 python3 启动 venv

无法使用 python3 启动 venv

当我尝试启动虚拟环境时,我得到:

~$ python3 -m venv homeassistant
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/gal/homeassistant/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

但是当我尝试安装 python3-venv 时,我得到了:

~$ sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-venv is already the newest version (3.6.7-1~18.04).
0 upgraded, 0 newly installed, 0 to remove and 38 not upgraded.

我应该安装了几个 Python 版本,但我将它们删除作为替代方案:

~$ sudo update-alternatives --config python3
There is only one alternative in link group python3 (providing /usr/bin/python3): /~$ sudo update-alternatives --config python3
There is only one alternative in link group python3 (providing /usr/bin/python3): /usr/bin/python3.7
Nothing to configure.usr/bin/python3.7
Nothing to configure.

Python版本是3.7.5:

~$ python3 --version
Python 3.7.5

操作系统版本是:

~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

我认为问题是由于“python3-venv 已经是最新版本 (3.6.7-1~18.04)”造成的,而我使用的版本是 3.7 而不是 3.6。但我不知道该怎么做。

谢谢您的任何建议。

答案1

您可以为您的 Python 版本安装一个 venv。

sudo apt-get install python3.7-venv

相关内容