Ubuntu 22.04 上的 Python3 和 pip3 依赖问题

Ubuntu 22.04 上的 Python3 和 pip3 依赖问题

我全新安装了 Ubuntu 22.04,并在其上运行了 sudo apt update 和 sudo apt upgrade。

现在我尝试创建一个 Python 虚拟环境,但遇到了依赖问题,我还没能解决。运行python3 -m venv myvenv要求我运行apt install python3.10-venv 执行此操作(当然使用 sudo)时,我收到此错误:

Reading package lists... Done
Building dependency tree... Done
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.10-venv : Depends: python3.10 (= 3.10.4-3ubuntu0.1) but 3.10.6-1~22.04 is to be installed
                   Depends: python3.10-distutils
E: Unable to correct problems, you have held broken packages.

我也尝试过sudo apt install python3-venv但是存在类似的依赖问题:

The following packages have unmet dependencies:
 python3-venv : Depends: python3.10-venv (>= 3.10.4-1~) but it is not going to be installed
                Depends: python3 (= 3.10.4-0ubuntu2) but 3.10.6-1~22.04 is to be installed
                Depends: python3-distutils (>= 3.9.10-2~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

我也尝试安装 pip,运行sudo apt install python3-pip并出现以下冲突:

The following packages have unmet dependencies:
 python3-distutils : Depends: python3-lib2to3 (= 3.10.4-0ubuntu1) but 3.10.6-1~22.04 is to be installed
E: Unable to correct problems, you have held broken packages.

我怎样才能解决这些问题?


编辑
根据要求:
$ apt-cache policy python3.10-venv:
python3.10-venv:
  Installed: (none)
  Candidate: 3.10.4-3ubuntu0.1
  Version table:
     3.10.4-3ubuntu0.1 500
        500 http://archive.ubuntu.com/ubuntu jammy-security/universe amd64 Packages
     3.10.4-3 500
        500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages

答案1

您的apt-cache policy输出显示您尚未jammy-updates启用。

  • 使能够jammy-updates
  • 跑步sudo apt update

然后与版本相关的 apt 错误将会消失。

相关内容