You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04重装python3-apt时遇apt_pkg模块缺失错误求助

解决 apt_pkg 模块缺失导致的dpkg配置失败问题

问题重现

运行命令:

sudo apt-get install python3-apt --reinstall

出现以下错误:

回溯(最近的调用最后):
文件"/usr/lib/update-notifier/package-data-downloader",第29行,在
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

dpkg: 处理软件包update-notifier-common(--configure)时出错:
已安装的update-notifier-common软件包的后安装脚本子进程返回错误退出状态1
dpkg: 依赖关系问题阻止配置update-notifier:
update-notifier依赖于update-notifier-common (= 3.192.54);然而:
软件包update-notifier-common尚未配置。

dpkg: 处理软件包update-notifier(--configure)时出错:
依赖关系问题 - 未配置
dpkg: 依赖关系问题阻止配置ubuntu-desktop:
ubuntu-desktop依赖于update-notifier;然而:
软件包update-notifier尚未配置。

dpkg: 处理软件包ubuntu-desktop(--configure)时出错:
依赖关系问题 - 未配置
dpkg: 依赖关系问题阻止配置ubuntu-desktop-minimal:
ubuntu-desktop-minimal依赖于update-notifier;然而:
软件包update-notifier尚未配置。

dpkg: 处理软件包ubuntu-desktop-minimal(--configure)时出错:
依赖关系问题 - 未配置
未写入 apport 报告,因为错误消息表明这是先前失败的后续错误。
未写入 apport 报告,因为错误消息表明这是先前失败的后续错误。
未写入 apport 报告,因为已达到MaxReports上限
处理时遇到错误:
update-notifier-common
update-notifier
ubuntu-desktop
ubuntu-desktop-minimal
E: 子进程/usr/bin/dpkg返回错误代码(1)

解决步骤

1. 修复apt_pkg模块的符号链接

问题根源是Python找不到apt_pkg模块,通常是符号链接缺失或错位。执行以下命令:

  • 查找apt_pkg的实际文件路径:
find /usr/lib/python3/dist-packages -name "apt_pkg.cpython-*.so"
  • 将找到的文件链接为apt_pkg.so(替换下面的路径为你实际找到的):
sudo ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-38-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.so

2. 重新配置所有未完成的dpkg包

sudo dpkg --configure -a

3. 重新安装python3-apt

sudo apt-get install python3-apt --reinstall

4. 修复依赖关系(如果上述步骤无效)

sudo apt-get clean && sudo apt-get update && sudo apt-get install --fix-broken

内容的提问来源于stack exchange,提问作者Gabriel1234

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 17:48:21