当我运行时sudo apt update
出现以下错误:
sh: 1: /usr/lib/cnf-update-db: not found
Reading package lists... Done
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
我认为问题可能与 Python 有关。运行后sudo apt-get install -f
,出现以下消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 to upgrade, 0 to newly install, 0 to remove and 19 not to upgrade.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up python3-wheel (0.30.0-0.2) ...
/var/lib/dpkg/info/python3-wheel.postinst: 6: /var/lib/dpkg/info/python3-wheel.postinst: py3compile: not found
dpkg: error processing package python3-wheel (--configure):
installed python3-wheel package post-installation script subprocess returned error exit status 127
Setting up python3-pip (9.0.1-2.3~ubuntu1.18.04.1) ...
/var/lib/dpkg/info/python3-pip.postinst: 6: /var/lib/dpkg/info/python3-pip.postinst: py3compile: not found
dpkg: error processing package python3-pip (--configure):
installed python3-pip package post-installation script subprocess returned error exit status 127
Setting up python3-setuptools (39.0.1-2) ...
/var/lib/dpkg/info/python3-setuptools.postinst: 6: /var/lib/dpkg/info/python3-setuptools.postinst: py3compile: not found
dpkg: error processing package python3-setuptools (--configure):
installed python3-setuptools package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
python3-wheel
python3-pip
python3-setuptools
E: Sub-process /usr/bin/dpkg returned an error code (1)
由于我对 Linux 还很陌生,有人能帮我解决这个问题吗?
运行后,sudo apt install --reinstall python3-minimal
问题似乎已经消失,现在一切似乎都运行正常(甚至终端也恢复了)。无论如何,这是 python -v 的结果:Python 2.7.15+
答案1
一年前有人问过这个问题,而且有同样的错误。解决方案是创建一个指向 python 的符号链接来修复此问题:
因此请检查链接 /usr/bin/python 指向的位置:
$ ls -la /usr/bin/python
lrwxrwxrwx 1 root root 9 Jan 24 2017 /usr/bin/python -> python2.7
It should point to python2, not to any python3 executable. If it points to python3 then do the following (man ln):
$ sudo rm -f /usr/bin/python
$ sudo ln -s /usr/bin/python2.7 /usr/bin/python
此后,apt-get/apt 将重新开始工作。
尝试 sudo apt-get update 时出错 - 与 Python 相关? 帖子中的错误显示:
sh 1: /usr/lib/cnf-update-db: not found
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Succes 'if /usr/bin/test -w /var/lib/command-not-found -a -e /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code