我在台式机上使用 Ubuntu 20.04.1。几个月前,我可能用 python3 文件覆盖了 python2 二进制文件,以使某些功能正常工作。(为什么任何正常系统仍然安装有 python2?)
无论如何,我只是尝试运行apt upgrade
但失败了,责任归咎于python-apt
包。
$ sudo apt upgrade
Preparing to unpack .../python-apt_2.0.0ubuntu0.20.04.2_amd64.deb ...
File "/usr/bin/pyclean", line 63
except (IOError, OSError), e:
^
SyntaxError: invalid syntax
dpkg: warning: old python-apt package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead ...
File "/usr/bin/pyclean", line 63
except (IOError, OSError), e:
SyntaxError: invalid syntax
dpkg: error processing archive /var/cache/apt/archives/python-apt_2.0.0ubuntu0.2
0.04.2_amd64.deb (--unpack):
new python-apt package pre-removal script subprocess returned error exit status
1
Traceback (most recent call last):
File "/usr/bin/pycompile", line 35, in <module>
from debpython.version import SUPPORTED, debsorted, vrepr, \
File "/usr/share/python/debpython/version.py", line 24, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
dpkg: error while cleaning up:
installed python-apt package post-installation script subprocess returned error
exit status 1
Errors were encountered while processing:
/var/cache/apt/archives/python-apt_2.0.0ubuntu0.20.04.2_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
我尝试清除该包但是也失败了:
$ apt purge python-apt
[...]
Do you want to continue? [Y/n]
dpkg: error processing package python-apt (--remove):
package is in a very bad inconsistent state; you should
reinstall it before attempting a removal
dpkg: too many errors, stopping
Errors were encountered while processing:
python-apt
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)
二进制文件如下所示:
$ ll /usr/bin | grep python
-rwxr-xr-x 1 root root 1057 Mar 13 2020 dh_python2*
lrwxrwxrwx 1 root root 23 Aug 4 07:16 pdb2.7 -> ../lib/python2.7/pdb.py*
lrwxrwxrwx 1 root root 23 Jul 28 08:59 pdb3.8 -> ../lib/python3.8/pdb.py*
lrwxrwxrwx 1 root root 31 Mar 13 2020 py3versions -> ../share/python3/py3versions.py*
lrwxrwxrwx 1 root root 7 Apr 15 2020 python -> python2*
lrwxrwxrwx 1 root root 9 Mar 13 2020 python2 -> python2.7*
-rwxr-xr-x 1 root root 5486352 Oct 25 14:14 python2.7*
lrwxrwxrwx 1 root root 9 Mar 13 2020 python3 -> python3.8*
-rwxr-xr-x 1 root root 5486352 Jul 28 08:59 python3.8*
-rwxr-xr-x 1 root root 384 Mar 27 2020 python3-futurize*
-rwxr-xr-x 1 root root 388 Mar 27 2020 python3-pasteurize*
lrwxrwxrwx 1 root root 29 Mar 13 2020 pyversions -> ../share/python/pyversions.py*
这是我的版本信息:
$ python --version
Python 3.8.5
$ python2 --version
Python 3.8.5
考虑到 中的符号链接,Python2/usr/bin
有点奇怪。有人有什么想法吗?
更新:我刚刚注意到该错误消息的不同部分:
"ModuleNotFoundError: No module named 'ConfigParser'"
我在网上看到有人写道 Python 3 将其称为“configparser”(小写)。这可能是问题所在吗?如果是,为什么其他人没有遇到这种情况?
答案1
由于某种原因,我需要重新创建 Python2 二进制文件。我找到了解决方案这一页 它的工作原理如下:
apt-get download python2.7-minimal
ar x python2.7-minimal_2.7.18-1~20.04_amd64.deb data.tar.xz
sudo tar xJf data.tar.xz -C / './usr/bin/python2.7'
rm data.tar.xz