执行sudo apt autoremove遇ModuleNotFoundError问题求助
解决
apt autoremove命令报错ModuleNotFoundError的问题 问题重现
执行sudo apt autoremove等apt命令时,出现以下错误:
ModuleNotFoundError: No module named 'six'ModuleNotFoundError: No module named 'requests_unixsocket'
即使通过pip list | grep six确认six已安装,重新安装两个包后问题仍存在。完整错误日志如下:
Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 76 not upgraded. 1 not fully installed or removed. After this operation, 0 B of additional disk space will be used. Setting up update-notifier-common (3.192.30.19) ... Traceback (most recent call last): File "/usr/lib/update-notifier/package-data-downloader", line 24, in <module> import debian.deb822 File "/usr/lib/python3/dist-packages/debian/deb822.py", line 240, in <module> import six ModuleNotFoundError: No module named 'six' Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 72, 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 32, in <module> import apport.fileutils File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 12, in <module> import os, glob, subprocess, os.path, time, pwd, sys, requests_unixsocket ModuleNotFoundError: No module named 'requests_unixsocket' Original exception was: Traceback (most recent call last): File "/usr/lib/update-notifier/package-data-downloader", line 24, in <module> import debian.deb822 File "/usr/lib/python3/dist-packages/debian/deb822.py", line 240, in <module> import six ModuleNotFoundError: No module named 'six' dpkg: error processing package update-notifier-common (--configure): installed update-notifier-common package post-installation script subprocess returned error exit status 1 Errors were encountered while processing: update-notifier-common E: Sub-process /usr/bin/dpkg returned an error code (1)
解决方案
问题根源是系统Python环境与pip安装的环境不一致:apt相关脚本调用的是系统Python,而pip默认可能将包安装到用户目录,系统脚本无法读取该路径。必须用系统包管理器安装对应deb包:
- 重新安装
six和requests_unixsocket的系统版本
sudo apt install --reinstall python3-six sudo apt install --reinstall python3-requests-unixsocket
- 修复未配置的
update-notifier-common包
sudo dpkg --configure update-notifier-common
如果上述命令无效,强制重新安装该包:
sudo apt install --reinstall update-notifier-common
- 验证修复
再次执行sudo apt autoremove或sudo apt update,确认报错消失。
内容的提问来源于stack exchange,提问作者Bruno Henrique Peixoto
相关产品推荐
相关产品推荐

