我使用 deadsnakes PPA 将 python3.10 安装在我的 Ubuntu 20.04 上。它运行良好,python3.8 仍然是我系统的 python3:
$ python3 -V
Python 3.8.10
但是,当我尝试使用 apt 升级系统包时,它现在会引发一个错误:
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libpython3.10 : Depends: libpython3.10-stdlib (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is installed
libpython3.10-dev : Depends: libpython3.10-stdlib (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is installed
python3.10 : Depends: libpython3.10-stdlib (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is installed
python3.10-minimal : Depends: libpython3.10-minimal (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
遵循上述建议没有帮助:
$ sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following additional packages will be installed:
libpython3.10-minimal libpython3.10-stdlib
The following packages will be upgraded:
libpython3.10-minimal libpython3.10-stdlib
2 upgraded, 0 newly installed, 0 to remove and 76 not upgraded.
14 not fully installed or removed.
Need to get 0 B/2 566 kB of archives.
After this operation, 68,6 kB disk space will be freed.
Do you want to continue? [Д/н] y
(Reading database ... 200427 files and directories currently installed.)
Preparing to unpack .../libpython3.10-stdlib_3.10.4-1+focal2_amd64.deb ...
Unpacking libpython3.10-stdlib:amd64 (3.10.4-1+focal2) over (3.10.4-1+focal1) ..
.
dpkg: error processing archive /var/cache/apt/archives/libpython3.10-stdlib_3.10
.4-1+focal2_amd64.deb (--unpack):
trying to overwrite '/usr/lib/python3.10/_sysconfigdata__linux_x86_64-linux-gnu
.py', which is also in package libpython3.10-minimal:amd64 3.10.4-1+focal1
Preparing to unpack .../libpython3.10-minimal_3.10.4-1+focal2_amd64.deb ...
Unpacking libpython3.10-minimal:amd64 (3.10.4-1+focal2) over (3.10.4-1+focal1) .
..
dpkg: error processing archive /var/cache/apt/archives/libpython3.10-minimal_3.1
0.4-1+focal2_amd64.deb (--unpack):
trying to overwrite '/usr/lib/python3.10/typing.py', which is also in package l
ibpython3.10-stdlib:amd64 3.10.4-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/libpython3.10-stdlib_3.10.4-1+focal2_amd64.deb
/var/cache/apt/archives/libpython3.10-minimal_3.10.4-1+focal2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
尝试卸载 python3.10 均无效:
$ sudo apt purge python3.10
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libpython3.10 : Depends: libpython3.10-stdlib (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is to be installed
libpython3.10-dev : Depends: libpython3.10-stdlib (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is to be installed
python3.10-dev : Depends: python3.10 (= 3.10.4-1+focal2) but it is not going to be installed
python3.10-minimal : Depends: libpython3.10-minimal (= 3.10.4-1+focal2) but 3.10.4-1+focal1 is to be installed
Recommends: python3.10 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
答案1
从 Deadsnakes PPA 安装两个 Python 3.10 版本失败的原因是打包时存在不应该发生的冲突。不幸的是,这是 PPA 维护人员必须修复的问题,而不是我们能修复的问题。
你确实问过如何消除PPA 中也有 Python 3.10,所以我会给你关于如何操作的说明。
您可以使用以下命令从 PPA 中清除所有 Python 3.10 位:
sudo apt purge {lib,}python3.10{,-dev,-minimal} libpython3.10-stdlib python3.10{-distutils,-lib2to3}
这将消除通过 Deadsnakes PPA 完整安装的 Python 3.10。(如果您使用的是 Ubuntu 22.04 并使用标准系统 Python,请不要执行此操作,仅当您使用 20.04 或其他受支持的 Ubuntu 和 Deadsnakes PPA 来获取 Python 3.10 时才执行此操作)