升级python3.10时,子进程/usr/bin/dpkg返回错误代码(1)。

apt upgrade:

$ sudo apt-get full-upgrade -y

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).

apt --fix-broken install:

$ 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 10 not upgraded.
9 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/n] y
(Reading database ... 279178 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+fo
cal1
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.10.4-1+focal2_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.10/typing.py', which is also in package libpython3.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软件包,但出现了“未满足的依赖关系”错误。
这个错误消息是什么意思,有没有办法修复它?

2你应该向提供给你使用的Python包的人报告这个错误。听起来像是一个打包错误,制作这些包的人应该知道这个问题。 - sarnold
3个回答

尝试移除有问题的软件包,例如libpython3.10-minimal和libpython3.10-stdlib。
sudo apt remove libpython3.10-minimal libpython3.10-stdlib

如果这里写着 --fix-broken 则需要手动删除,像这样

ls -l /var/lib/dpkg/info | grep -i libpython3.10-minimal

这显示了包含libpython3.10-minimal的截断文件名。现在将其移动到另一个目录中。
sudo mv /var/lib/dpkg/info/libpython3.10-minimal:amd64.* /tmp

然后做
sudo apt --fix-broken install

它会显示找不到libpython3.10-minimal,然后重新安装它。

出了什么问题,请您详细说明一下?为什么会出现这个问题,以及为什么删除/var/lib/dpkg/info/libpython3.10-minimal:amd64.*后问题得到解决? - Udesh
10@UdeshRanjan 一个文件从-stdlib移动到-minimal,另一个文件从-minimal移动到-stdlib,因此没有一个可以先行而不覆盖另一个文件。删除它们两个都清除了这个条件(尽管我会使用dpkg --remove --force-all而不是伪造/var/lib/dpkg/info)。 - hobbs
在我的情况下,我必须执行以下操作:在最后执行sudo apt install libpython3.10-minimal,因为sudo apt --fix-broken install命令没有尝试重新安装软件包。 - mcarans
3我按照 @hobbs 的建议,在 Ubuntu 20.04 LTS 上轻松解决了这个问题:首先执行 sudo dpkg --remove --force-all libpython3.10-minimal libpython3.10-stdlib,然后执行 sudo apt install libpython3.10-minimal libpython3.10-stdlib - apocalipisis
我猜在我的情况下,问题发生是因为我从源代码编译了Python3.10。现在通过这个答案已经修复了。 - Emil
救命稻草。花了最后3个小时试图完全删除deadsnakes ppa与有问题的软件包,安装两次失败,而我所需要的只是使用这两个简单的命令。 - Igor

正如Rice和Hobbs所说,问题在于一个文件从一个包移动到另一个包,而在更新过程中它们互相干扰。我按照他们的建议强制升级,但是不得不稍作调整。以下是我最终采取的做法:
sudo dpkg --force-all --remove libpython3.10-stdlib libpython3.10-minimal

这会强制两个冲突的软件包进行卸载,即使其他软件依赖于它们。
sudo apt-get install libpython3.10-stdlib libpython3.10-minimal

重新安装它们,而不会相互干扰。此时,sudo apt --fix-broken install 也可能起作用,但我没有尝试过。

答案从这里调整而来

不需要移除它们,强制安装一个软件包,然后修复其余的问题。

sudo dpkg -i --force-overwrite /var/cache/apt/archives/libpython3.10-stdlib_3.10.4-1+focal2_amd64.deb
sudo apt --fix-broken install