添加和删​​除 Bodhi 存储库后运行 apt update 时出现与 Python 相关的错误

添加和删​​除 Bodhi 存储库后运行 apt update 时出现与 Python 相关的错误

运行更新时出错:

thufir@bot:~$ sudo apt update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Hit:2 http://ca.archive.ubuntu.com/ubuntu bionic InRelease
Get:3 http://ca.archive.ubuntu.com/ubuntu bionic-updates InRelease [83.2 kB]        
Hit:4 http://ca.archive.ubuntu.com/ubuntu bionic-backports InRelease 
Fetched 166 kB in 1s (138 kB/s)
Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 8, in <module>
    from CommandNotFound.db.creator import DbCreator
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
    import apt_pkg
ImportError: /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so: symbol _ZN13debListParser12ParseDependsEPKcS1_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_RjRKbSB_SB_RKS7_ version APTPKG_5.0 not defined in file libapt-pkg.so.5.0 with link time reference
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ImportError: /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so: symbol _ZN13debListParser12ParseDependsEPKcS1_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_RjRKbSB_SB_RKS7_ version APTPKG_5.0 not defined in file libapt-pkg.so.5.0 with link time reference

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 8, in <module>
    from CommandNotFound.db.creator import DbCreator
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
    import apt_pkg
ImportError: /usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so: symbol _ZN13debListParser12ParseDependsEPKcS1_RNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_RjRKbSB_SB_RKS7_ version APTPKG_5.0 not defined in file libapt-pkg.so.5.0 with link time reference
Reading package lists... Done
W: Problem unlinking the file auxfiles - Clean (21: Is a directory)
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code
thufir@bot:~$ 

此错误可能是由于尝试添加bodhi 的仓库。sources.list文件:

thufir@bot:~$ cat /etc/apt/sources.list
#deb cdrom:[Ubuntu 18.04 LTS _Bionic Beaver_ - Release amd64 (20180426)]/ bionic main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ca.archive.ubuntu.com/ubuntu/ bionic main restricted
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ca.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ca.archive.ubuntu.com/ubuntu/ bionic universe
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic universe
deb http://ca.archive.ubuntu.com/ubuntu/ bionic-updates universe
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ca.archive.ubuntu.com/ubuntu/ bionic multiverse
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic multiverse
deb http://ca.archive.ubuntu.com/ubuntu/ bionic-updates multiverse
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ca.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src http://ca.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://security.ubuntu.com/ubuntu bionic-security main restricted
# deb-src http://security.ubuntu.com/ubuntu bionic-security main restricted
deb http://security.ubuntu.com/ubuntu bionic-security universe
# deb-src http://security.ubuntu.com/ubuntu bionic-security universe
deb http://security.ubuntu.com/ubuntu bionic-security multiverse
# deb-src http://security.ubuntu.com/ubuntu bionic-security multiverse

#deb [trusted=yes] http://packages.bodhilinux.com/bodhi xenial b4main
thufir@bot:~$ 

请注意bodhi,最后一行已被注释掉。 操作系统:

thufir@bot:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:    18.04
Codename:   bionic

合适的版本:

thufir@bot:~$ apt-cache policy apt
apt:
  Installed: 2.2.12~bodhi2
  Candidate: 2.2.12~bodhi2
  Version table:
 *** 2.2.12~bodhi2 100
        100 /var/lib/dpkg/status
     1.6.1 500
        500 http://ca.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

也许问题是更新失败?

答案1

看起来您安装了一些第三方版本的apt软件包,但保留了随附的、显然不兼容的libapt-pkg5.0软件包,因为它来自 Canonical 的存储库。

通常情况下您可以使用以下命令强制将软件包升级到当前 Ubuntu 版本可用的最新版本:

sudo apt install {PACKAGE_NAME,...}/$(lsb_release -sc)

然而在这种情况下Apt 本身受到影响并出现问题,因此您需要:

  1. 从软件包存储库手动下载软件包 (aptlibapt-pkg5.0)。

    1. 确保软件包的页面适用于你的 Ubuntu 版本(查看顶部附近),
    2. 滚动到每个包页面底部的下载部分,
    3. 单击您的架构的链接,
    4. 选择合适的下载镜像并
    5. 将包文件存储在您可以记住以便于下一步使用的位置,例如/tmp
  2. 使用以下命令安装下载的 Deb 包dpkg

    cd /tmp
    sudo dpkg -i {apt,libapt-pkg5.0}_*.deb
    
  3. 更新您的软件包以验证 Apt 是否正常工作,并确保您拥有最新版本:

    sudo apt update
    sudo apt upgrade
    

相关内容