update-notifier报错AttributeError#
E: 未知错误:“<class ‘AttributeError’>”(module ‘apt_pkg’ has no attribute ‘Error’)。
首先查到该服务在/usr/lib/update-notifier/路径下存在一些脚本,其中apt-check -> apt_check.py就是元凶。
在我的系统中,报错的代码段如下:
1
2
3
4
5
6
7
8
9
10
11
| import apt_pkg
...
def get_apt_pkg_esm_cache():
...
try:
esm_cache = apt_pkg.Cache(progress=None)
except apt_pkg.Error:
esm_cache = None
|
**apt_pkg.Error**属性不存在,而从《python-apt Navigation》来看,是存在的,且:
It inherits from SystemError, so make sure to catch this class first.
而apt_pkg是一个动态库:
1
2
3
4
| import apt_pkg
apt_pkg.__file__
# '/usr/lib/python2.7/dist-packages/apt_pkg.x86_64-linux-gnu.so'
|
估计是版本有问题,重装一下:
1
2
3
| # 按照系统使用的python版本
sudo apt install --reinstall python-apt
sudo apt install --reinstall python3-apt
|
没效果,直接改文件:
1
2
| # except apt_pkg.Error:
except SystemError:
|
完毕。