由于依赖项未得到满足,无法创建 venv

由于依赖项未得到满足,无法创建 venv

我在 VirtualBox 上运行Ubuntu 18.04.5 LTS。我正在运行Python 3.6.9

当我尝试创建虚拟环境时,sudo python3 -m venv env得到以下信息:

admin@admin-VirtualBox:~/Desktop/project$ sudo python3 -m venv .venv
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/admin/Desktop/project/.venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

admin@admin-VirtualBox:~/Desktop/project$ python3 --version
Python 3.6.9
admin@admin-VirtualBox:~/Desktop/project$ sudo apt-get install python3.6-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3.6-venv : Depends: python3.6 (= 3.6.5-3) but 3.6.9-1~18.04ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.
admin@admin-VirtualBox:~/Desktop/project$ 

我研究后发现python3已经venv预装了。我认为存在一些损坏的依赖关系。

我试过:

admin@admin-VirtualBox:~/Desktop/project$ sudo apt-cache policy python3.6-venv python3.6 python3
python3.6-venv:
  Installed: (none)
  Candidate: 3.6.5-3
  Version table:
     3.6.5-3 500
        500 http://at.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
python3.6:
  Installed: 3.6.9-1~18.04ubuntu1.1
  Candidate: 3.6.9-1~18.04ubuntu1.1
  Version table:
 *** 3.6.9-1~18.04ubuntu1.1 100
        100 /var/lib/dpkg/status
     3.6.5-3 500
        500 http://at.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
python3:
  Installed: 3.6.7-1~18.04
  Candidate: 3.6.7-1~18.04
  Version table:
 *** 3.6.7-1~18.04 100
        100 /var/lib/dpkg/status
     3.6.5-3 500
        500 http://at.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

有什么建议可以解决这个问题吗?问题是什么?

感谢您的回复!

答案1

  1. 跑步software-properties-gtk

    第一个选项卡:启用main,,universe第二个选项卡:启用securityupdates

  2. 退出或运行时更新列表

    sudo apt update

  3. 安装虚拟环境模块(我希望它安装在 vanilla 镜像上)

    sudo apt install python3.6-venv

  4. 不使用创建虚拟环境sudo

    python3 -m venv .venv

顺便说一句,最好python3使用以下方法确认链接版本

ls -l $(which python3)

相关内容