未满足的依赖关系 python3.9

我正在尝试更新Ubuntu并纠正一些系统设置,但是我遇到了一个问题,已经困扰我一个多星期了。
当我输入sudo apt-get install时,我得到的结果是:
The following packages have unmet dependencies.
 python3.9 : Depends: libpython3.9-stdlib (= 3.9.5-3~20.04.1) but 3.9.5-1+bionic1 is installed
 python3.9-minimal : Depends: libpython3.9-minimal (= 3.9.5-3~20.04.1) but 3.9.5-1+bionic1 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.9-minimal libpython3.9-stdlib
The following packages will be upgraded:
  libpython3.9-minimal libpython3.9-stdlib
2 to upgrade, 0 to newly install, 0 to remove and 33 not to upgrade.
2 not fully installed or removed.
Need to get 0 B/2,532 kB of archives.
After this operation, 483 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 200853 files and directories currently installed.)
Preparing to unpack .../libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb ...
Unpacking libpython3.9-stdlib:amd64 (3.9.5-3~20.04.1) over (3.9.5-1+bionic1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py', which is also in package libpython3.
9-minimal:amd64 3.9.5-1+bionic1
Preparing to unpack .../libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb ...
Unpacking libpython3.9-minimal:amd64 (3.9.5-3~20.04.1) over (3.9.5-1+bionic1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.9/typing.py', which is also in package libpython3.9-stdlib:amd64 3.9.5-1+bionic1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb
 /var/cache/apt/archives/libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

我尝试了几种方法,并在一些论坛上搜索错误,但是我找不到解决方案。这真的让我感到困惑。
我甚至尝试了删除:
$ sudo apt remove libpython3.9-minimal/bionic libpython3.9-stdlib/bionic python3.9-minimal/focal-updates
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Selected version '3.9.5-1+bionic1' (New Python Versions:18.04/bionic [amd64]) for 'libpython3.9-minimal'
Selected version '3.9.5-1+bionic1' (New Python Versions:18.04/bionic [amd64]) for 'libpython3.9-stdlib'
Selected version '3.9.5-3~20.04.1' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'python3.9-minimal'
Selected version '3.9.5-3~20.04.1' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'libpython3.9-minimal' because of 'python3.9-minimal'
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies.
 python3.9 : Depends: python3.9-minimal (= 3.9.5-3~20.04.1) but it is not going to be installed
             Depends: libpython3.9-stdlib (= 3.9.5-3~20.04.1) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

任何帮助都将是很棒的!添加了以下内容
$ apt-cache policy python3.9 libpython3.9-stdlib libpython3.9-minimal python3.9-minimal 

Installed: 3.9.5-3~20.04.1
  Candidate: 3.9.5-3~20.04.1
  Version table:
 *** 3.9.5-3~20.04.1 500
        500 ://gb.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        500 ://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
        100 /var/lib/dpkg/status
     3.9.5-1+focal1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 Packages
     3.9.5-1+bionic1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 Packages
libpython3.9-stdlib:
  Installed: 3.9.5-1+bionic1
  Candidate: 3.9.5-3~20.04.1
  Version table:
     3.9.5-3~20.04.1 500
        500 ://gb.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        500 ://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
     3.9.5-1+focal1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 Packages
 *** 3.9.5-1+bionic1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status
libpython3.9-minimal:
  Installed: 3.9.5-1+bionic1
  Candidate: 3.9.5-3~20.04.1
  Version table:
     3.9.5-3~20.04.1 500
        500 ://gb.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        500 ://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
     3.9.5-1+focal1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 Packages
 *** 3.9.5-1+bionic1 500
        500 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status
libpython3.9-minimal:
  Installed: 3.9.5-1+bionic1
  Candidate: 3.9.5-3~20.04.1
  Version table:
     3.9.5-3~20.04.1 500
        500 ://gb.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        500 ://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
     3.9.5-1+focal1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 Packages
 *** 3.9.5-1+bionic1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status
python3.9-minimal:
  Installed: 3.9.5-3~20.04.1
  Candidate: 3.9.5-3~20.04.1
  Version table:
 *** 3.9.5-3~20.04.1 500
        500 ://gb.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages
        500 ://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages
        100 /var/lib/dpkg/status
     3.9.5-1+focal1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 Packages
     3.9.5-1+bionic1 500
        500 ://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 Packages

我跑了。
~/Downloads$ sudo ppa-purge ppa:deadsnakes/ppa # first for bionic

这是一个结果。
sudo ppa-purge ppa:deadsnakes/ppa # first for bionic
Updating packages lists
PPA to be removed: deadsnakes ppa
Package revert list generated:
 libpython3.8:amd64/focal libpython3.8-minimal:amd64/focal libpython3.8-stdlib:amd64/focal 
libpython3.9-minimal:amd64/focal libpython3.9-stdlib:amd64/focal python3.8/focal python3.8-minimal/focal

然后是以下内容:
understudy@understudy-System-Product-Name:~/Downloads$ sudo ppa-purge ppa:deadsnakes/ppa # second for focal
Updating packages lists
PPA to be removed: deadsnakes ppa
Warning:  Could not find package list for PPA: deadsnakes ppa
understudy@understudy-System-Product-Name:~/Downloads$ sudo ppa-purge ppa:deadsnakes/ppa # first for bionic
Updating packages lists
PPA to be removed: deadsnakes ppa
Warning:  Could not find package list for PPA: deadsnakes ppa

understudy@understudy-System-Product-Name:~/Downloads$ sudo apt-get install python3.9=3.9.5-3~20.04.1 libpython3.9-stdlib=3.9.5-3~20.04.1 \
> libpython3.9-minimal=3.9.5-3~20.04.1 python3.9-minimal=3.9.5-3~20.04.1 --reinstall
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libffi6 libncursesw5 libreadline7 libtinfo5
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  libpython3.9-minimal libpython3.9-stdlib
2 to upgrade, 0 to newly install, 2 reinstalled, 0 to remove and 36 not to upgrade.
7 not fully installed or removed.
Need to get 0 B/2,532 kB of archives.
After this operation, 483 kB of additional disk space will be used.
E: Internal Error, No file name for python3.9-minimal:amd64

还似乎不喜欢它
Disabling deadsnakes PPA from /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-focal.list
Disabling deadsnakes PPA from /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-bionic.list
Updating packages lists
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Selected version '3.8.5-1~20.04.3' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'libpython3.8'
Selected version '3.8.5-1~20.04.3' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'libpython3.8-minimal'
Selected version '3.8.5-1~20.04.3' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'libpython3.8-stdlib'
Selected version '3.9.5-3~20.04.1' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'libpython3.9-minimal'
Selected version '3.9.5-3~20.04.1' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'libpython3.9-stdlib'
Selected version '3.8.5-1~20.04.3' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'python3.8'
Selected version '3.8.5-1~20.04.3' (Ubuntu:20.04/focal-updates, Ubuntu:20.04/focal-security [amd64]) for 'python3.8-minimal'
The following packages were automatically installed and are no longer required:
  libffi6 libncursesw5 libreadline7 libtinfo5
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  python3.8-venv python3.8-doc
The following packages will be upgraded:
  libpython3.9-minimal libpython3.9-stdlib
The following packages will be DOWNGRADED:
  libpython3.8 libpython3.8-minimal libpython3.8-stdlib python3.8 python3.8-minimal
2 to upgrade, 0 to newly install, 5 to downgrade, 0 to remove and 36 not to upgrade.
2 not fully installed or removed.
Need to get 6,280 kB/8,813 kB of archives.
After this operation, 1,083 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8 amd64 3.8.5-1~20.04.3 [1,624 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 python3.8 amd64 3.8.5-1~20.04.3 [373 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8-stdlib amd64 3.8.5-1~20.04.3 [1,671 kB]
Get:4 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 python3.8-minimal amd64 3.8.5-1~20.04.3 [1,897 kB]
Get:5 http://gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 libpython3.8-minimal amd64 3.8.5-1~20.04.3 [715 kB]
Fetched 6,280 kB in 6s (969 kB/s)                                                                                      
(Reading database ... 200853 files and directories currently installed.)
Preparing to unpack .../0-libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb ...
Unpacking libpython3.9-stdlib:amd64 (3.9.5-3~20.04.1) over (3.9.5-1+bionic1) ...
dpkg: error processing archive /tmp/apt-dpkg-install-vTH1pX/0-libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py', which is also in package libpython3.9-minimal:amd64 3.9.5-1+bionic1
Preparing to unpack .../1-libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb ...
Unpacking libpython3.9-minimal:amd64 (3.9.5-3~20.04.1) over (3.9.5-1+bionic1) ...
dpkg: error processing archive /tmp/apt-dpkg-install-vTH1pX/1-libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.9/typing.py', which is also in package libpython3.9-stdlib:amd64 3.9.5-1+bionic1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
dpkg: warning: downgrading libpython3.8:amd64 from 3.8.10-1+bionic1 to 3.8.5-1~20.04.3
Preparing to unpack .../2-libpython3.8_3.8.5-1~20.04.3_amd64.deb ...
Unpacking libpython3.8:amd64 (3.8.5-1~20.04.3) over (3.8.10-1+bionic1) ...
dpkg: warning: downgrading python3.8 from 3.8.10-1+bionic1 to 3.8.5-1~20.04.3
Preparing to unpack .../3-python3.8_3.8.5-1~20.04.3_amd64.deb ...
Unpacking python3.8 (3.8.5-1~20.04.3) over (3.8.10-1+bionic1) ...
dpkg: warning: downgrading libpython3.8-stdlib:amd64 from 3.8.10-1+bionic1 to 3.8.5-1~20.04.3
Preparing to unpack .../4-libpython3.8-stdlib_3.8.5-1~20.04.3_amd64.deb ...
Unpacking libpython3.8-stdlib:amd64 (3.8.5-1~20.04.3) over (3.8.10-1+bionic1) ...
dpkg: warning: downgrading python3.8-minimal from 3.8.10-1+bionic1 to 3.8.5-1~20.04.3
Preparing to unpack .../5-python3.8-minimal_3.8.5-1~20.04.3_amd64.deb ...
Unpacking python3.8-minimal (3.8.5-1~20.04.3) over (3.8.10-1+bionic1) ...
dpkg: warning: downgrading libpython3.8-minimal:amd64 from 3.8.10-1+bionic1 to 3.8.5-1~20.04.3
Preparing to unpack .../6-libpython3.8-minimal_3.8.5-1~20.04.3_amd64.deb ...
Unpacking libpython3.8-minimal:amd64 (3.8.5-1~20.04.3) over (3.8.10-1+bionic1) ...
Errors were encountered while processing:
 /tmp/apt-dpkg-install-vTH1pX/0-libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb
 /tmp/apt-dpkg-install-vTH1pX/1-libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
/usr/local/bin/ppa-purge: line 191: aptitude: command not found
Warning:  Something went wrong, packages may not have been reverted

最新修复尝试之后
understudy@understudy-System-Product-Name:~$ # sudo apt-get install ppa-purge
understudy@understudy-System-Product-Name:~$ cd ~/Downloads
understudy@understudy-System-Product-Name:~/Downloads$ sudo apt-get download ppa-purge
[sudo] password for understudy: 
understudy@understudy-System-Product-Name:~/Downloads$ dpkg -x ppa-purge_0.2.8+bzr63_all.deb ppap
understudy@understudy-System-Product-Name:~/Downloads$ sudo cp ppap/usr/sbin/ppa-purge /usr/local/bin/
understudy@understudy-System-Product-Name:~/Downloads$ sudo ppa-purge ppa:deadsnakes/ppa # first for bionic
Updating packages lists
PPA to be removed: deadsnakes ppa
Warning:  Could not find package list for PPA: deadsnakes ppa
understudy@understudy-System-Product-Name:~/Downloads$ sudo ppa-purge ppa:deadsnakes/ppa # second for focal
Updating packages lists
PPA to be removed: deadsnakes ppa
Warning:  Could not find package list for PPA: deadsnakes ppa

understudy@understudy-System-Product-Name:~/Downloads$ sudo apt-get install python3.9=3.9.5-3~20.04.1 libpython3.9-stdlib=3.9.5-3~20.04.1 \
> libpython3.9-minimal=3.9.5-3~20.04.1 python3.9-minimal=3.9.5-3~20.04.1 --reinstall
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libffi6 libncursesw5 libreadline7 libtinfo5
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  libpython3.9-minimal libpython3.9-stdlib
2 to upgrade, 0 to newly install, 2 reinstalled, 0 to remove and 36 not to upgrade.
7 not fully installed or removed.
Need to get 0 B/2,532 kB of archives.
After this operation, 483 kB of additional disk space will be used.
E: Internal Error, No file name for python3.9-minimal:amd64
understudy@understudy-System-Product-Name:~/Downloads$ sudo apt-get install aptitude
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.
 aptitude : Depends: aptitude-common (= 0.8.12-1ubuntu4) but it is not going to be installed
            Depends: libcwidget4 (>= 0.5.18-1) but it is not going to be installed
            Recommends: libparse-debianchangelog-perl but it is not going to be installed
 python3.9 : Depends: libpython3.9-stdlib (= 3.9.5-3~20.04.1) but 3.9.5-1+bionic1 is to be installed
 python3.9-minimal : Depends: libpython3.9-minimal (= 3.9.5-3~20.04.1) but 3.9.5-1+bionic1 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

在执行了sudo apt --fix-broken install命令之后
[sudo] password for understudy: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  libffi6 libncursesw5 libreadline7 libtinfo5
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libpython3.9-minimal libpython3.9-stdlib
The following packages will be upgraded:
  libpython3.9-minimal libpython3.9-stdlib
2 to upgrade, 0 to newly install, 0 to remove and 36 not to upgrade.
7 not fully installed or removed.
Need to get 0 B/2,532 kB of archives.
After this operation, 483 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 200857 files and directories currently installed.)
Preparing to unpack .../libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb ...
Unpacking libpython3.9-stdlib:amd64 (3.9.5-3~20.04.1) over (3.9.5-1+bionic1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py', which is also in package libpython3.9-minimal:amd64 3.9.5-1+bionic1
Preparing to unpack .../libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb ...
Unpacking libpython3.9-minimal:amd64 (3.9.5-3~20.04.1) over (3.9.5-1+bionic1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb (--unpack):
 trying to overwrite '/usr/lib/python3.9/typing.py', which is also in package libpython3.9-stdlib:amd64 3.9.5-1+bionic1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb
 /var/cache/apt/archives/libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

1你的 Ubuntu 版本是什么?为什么会混合使用 18.04 (bionic) 和 20.04 (focal) 的软件源?请在问题中附上 apt-cache policy python3.9 libpython3.9-stdlib libpython3.9-minimal python3.9-minimal 的输出结果。 - N0rbert
你好,我将输出放在原帖中,因为它太大了。 - THeUNderstudy
发行商ID:Ubuntu 描述:Ubuntu 20.04.2 LTS 版本:20.04 代号:focal - THeUNderstudy
为什么你把18.04(bionic)和20.04(focal)的软件源混在一起了?- 我不确定为什么会发生这种情况。 - THeUNderstudy
使用sudo apt-get install aptitude命令安装Aptitude。 - N0rbert
请展示您当前的存储库列表 - 执行命令 grep "^deb\ " -r /etc/apt/ --include=*.list 和 Python 源码 apt-cache policy python3.9 libpython3.9-stdlib libpython3.9-minimal python3.9-minimal - 将输出添加到问题中。如果内容较长,请使用 Pastebin。 - N0rbert
我遇到了同样的问题,运行sudo apt --fix-broken install解决了它。 - LeonardoAyala
8个回答

这对我有用。我找到了出错的软件包,并使用dpkg进行安装。
sudo dpkg -i --force-all /var/cache/apt/archives/libpython3.9-stdlib_3.9.12-1+bionic2_amd64.deb
sudo dpkg -i --force-all /var/cache/apt/archives/libpython3.9-minimal_3.9.12-1+bionic2_amd64.deb

注意:您可能有不同版本的这些软件包,可以使用ls /var/cache/apt/archives/ | grep libpython3.9-找到它们。
然后我可以进行更新:
sudo apt-get update -y && sudo apt-get install --fix-broken

1在我的情况下,它说最小化是标准库的依赖,所以我必须先安装最小化。但那些就是文件。谢谢。 - WesternGun
太棒了,这个帮助了我三个月以来一直出现的错误!非常感谢你!!! - rom

你添加了不必要的PPA软件源。要删除它,请使用以下命令:
# sudo apt-get install ppa-purge
cd ~/Downloads
apt-get download ppa-purge
dpkg -x ppa-purge_0.2.8+bzr63_all.deb ppap
sudo cp ppap/usr/sbin/ppa-purge /usr/local/bin/

sudo ppa-purge ppa:deadsnakes/ppa # first for bionic
sudo ppa-purge ppa:deadsnakes/ppa # second for focal

然后从官方的20.04 LTS存储库中重新安装正常的Python版本:
sudo apt-get install python3.9=3.9.5-3~20.04.1 libpython3.9-stdlib=3.9.5-3~20.04.1 \
libpython3.9-minimal=3.9.5-3~20.04.1 python3.9-minimal=3.9.5-3~20.04.1 --reinstall

然后使用以下命令安装Aptitude

sudo apt-get install aptitude

通过以下方式恢复软件包安装

sudo add-apt-repository main
sudo add-apt-repository universe
sudo add-apt-repository multiverse
sudo add-apt-repository restricted

sudo apt-get update
sudo apt-get install -f
sudo dpkg -i --force-all /var/cache/apt/archives/libpython3.9-stdlib_3.9.5-3~20.04.1_amd64.deb /var/cache/apt/archives/libpython3.9-minimal_3.9.5-3~20.04.1_amd64.deb

sudo dpkg --configure -a
sudo aptitude install python3.9=3.9.5-3~20.04.1 libpython3.9-stdlib=3.9.5-3~20.04.1 \
libpython3.9-minimal=3.9.5-3~20.04.1 python3.9-minimal=3.9.5-3~20.04.1
sudo aptitude dist-upgrade

N0rbert非常感谢你 - 看起来好像起作用了!我真的很感激,我已经病了很久 :-) - THeUNderstudy
我很高兴,现在问题已经解决了。所以你可以点击我回答左边的勾号来标记这个问题已解决。 - N0rbert

这篇文章帮助了我dpkg错误代码1
sudo dpkg --configure -a
sudo apt remove --purge python3.9-minimal python3.9
sudo apt autoremove
sudo apt upgrade

直接运行 sudo apt autoremove --purge python3.9-minimal python3.9 不是更快吗? - Igor Foxly

诊断:

查看sudo apt upgrade的输出:

myself@box:~$ sudo apt upgrade
[sudo] password for myself: 
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.
 python3.9 : Depends: libpython3.9-stdlib (= 3.9.5-3~20.04.1) but 3.9.5-1+bionic1 is installed
 python3.9-minimal : Depends: libpython3.9-minimal (= 3.9.5-3~20.04.1) but 3.9.5-1+bionic1 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

结论:一些 Python 3.9 的包存在问题。

概述:

列出所有的Python 3.9包。在实施解决方案之前和之后,比较这个列表是很有用的。

# Command:
sudo dpkg -l | grep 'python3\.9' | awk '{print $2}'

# Output:
libpython3.9-minimal:amd64
libpython3.9-stdlib:amd64
python3.9
python3.9-distutils
python3.9-lib2to3
python3.9-minimal
python3.9-venv

解决方案:
无需删除/清除deadsnakes ppa。
  • 使用以下命令删除所有Python 3.9软件包:

    myself@box:~$ sudo apt --fix-missing purge $(dpkg -l | grep 'python3\.9' | awk '{print $2}')
    
  • 输入Y以执行列出的软件包的删除操作。

  • 再次安装相同的软件包:

    • 备选方案A)更慢且更智能的版本:仅安装您知道要安装的软件包,apt会将其标记为手动安装:

      myself@box:~$ sudo apt install python3.9 python3.9-venv
      

      然后查看其他软件包是否作为依赖项自动安装。如果没有,请手动安装其他缺失的软件包。

    • 备选方案B)更快且更简单的版本:从由apt --fix-missing purge创建的列表中复制软件包名称,去除星号并安装它们(再次安装):

      myself@box:~$ sudo apt install libpython3.9-minimal libpython3.9-stdlib python3.9 python3.9-minimal python3.9-venv
      
  • 可选:使用上述“Overview”命令检查您现在安装的软件包是否与实施解决方案之前相同。


  • 命令的来源和每个部分的解释(#1)可以在这里找到https://askubuntu.com/a/1402567


    我在尝试安装需要较旧版本的Python软件后遇到了同样的问题,这个软件来自于Deadsnakes PPA。这让我感到非常害怕,因为即使通过synaptic也无法降级Python3.9而不影响重要的系统包,这可能是无法恢复的。
    以下命令对我有效。显然,您需要将下面的软件包版本(使用sudo synapticapt-cache policy python3.9进行检查)替换为您所需的系统版本的Python,并在清除deadsnakes PPA之后执行该命令:
    sudo ppa-purge ppa:deadsnakes/ppa
    sudo apt-get update
    sudo apt-get install -yf --allow-downgrades libpython3.9-dev=3.9.7-2build1 python3.9-minimal=3.9.7-2build1 libpython3.9-minimal=3.9.7-2build1 python3.9-dev=3.9.7-2build1
    

    你替我修好了!谢谢2022年的陌生人。 - NPike


    我遇到了同样的问题,并且通过以下方法解决了:
    sudo dpkg -i --force-all /var/cache/apt/archives/libpython3.9-stdlib_3.9.5-3ubuntu0~20.04.1_amd64.deb /var/cache/apt/archives/libpython3.9-minimal_3.9.5-3ubuntu0~20.04.1_amd64.deb

    我遇到了一个类似但略有不同的问题:
    错误:
    jetsonagx@jetsonagx-desktop:~/Downloads/nvidia/sdkm_downloads$ sudo apt-get install python3.9
        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:
         python3.9 : Depends: python3.9-minimal (= 3.9.5-3ubuntu0~20.04.1) but it is not going to be installed
                 Depends: libpython3.9-stdlib (= 3.9.5-3ubuntu0~20.04.1) but it is not going to be installed             
        E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
    

    注意!在显示的错误中没有安装+bionic1文本。
    我通过手动下载和安装.deb文件来解决了这个问题。
    # download required files
    $ wget http://ports.ubuntu.com/pool/universe/p/python3.9/python3.9-minimal_3.9.5-3ubuntu0~20.04.1_arm64.deb     # python3.9-minimal
    $ wget http://ports.ubuntu.com/pool/universe/p/python3.9/libpython3.9-minimal_3.9.5-3ubuntu0~20.04.1_arm64.deb  # libpython3.9-minimal (python3.9-minimal required it)
    $ wget http://ports.ubuntu.com/pool/universe/p/python3.9/libpython3.9-stdlib_3.9.5-3ubuntu0~20.04.1_arm64.deb   # python3.9-sdlib
    
    # install downloaded files
    $ sudo dpkg -i libpython3.9-minimal_3.9.5-3ubuntu0~20.04.1_arm64.deb    
    $ sudo dpkg -i libpython3.9-stdlib_3.9.5-3ubuntu0~20.04.1_arm64.deb
    $ sudo apt-get install python3.9
    

    希望对某人有所帮助。

    • 相关问题