ModuleNotFoundError: 没有名为“apt_pkg”的模块

yod*_*ama 2 linux debian python

在我的 linux raspbian 发行版上安装 python 3.6.8 后,当我尝试安装 libunwind8 时出现错误:

ModuleNotFoundError: No module named 'apt_pkg'
Run Code Online (Sandbox Code Playgroud)

调试后我发现以下 SO 页面错误答案没有帮助:导入错误没有名为 apt-pkg 的模块

给出的答案说安装python-apt,我做了,只是得到以下错误:

Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 29, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
(Reading database ... 41347 files and directories currently installed.)
Preparing to unpack .../gnupg-agent_2.1.18-8~deb9u4_armhf.deb ...
Unpacking gnupg-agent (2.1.18-8~deb9u4) over (2.1.18-8~deb9u3) ...
Setting up gnupg-agent (2.1.18-8~deb9u4) ...
(Reading database ... 41347 files and directories currently installed.)
Preparing to unpack .../gnupg_2.1.18-8~deb9u4_armhf.deb ...
Unpacking gnupg (2.1.18-8~deb9u4) over (2.1.18-8~deb9u3) ...
Setting up gnupg (2.1.18-8~deb9u4) ...
Selecting previously unselected package dirmngr.
(Reading database ... 41347 files and directories currently installed.)
Preparing to unpack .../dirmngr_2.1.18-8~deb9u4_armhf.deb ...
Unpacking dirmngr (2.1.18-8~deb9u4) ...
Selecting previously unselected package python-apt.
Preparing to unpack .../python-apt_1.1.0~beta5_armhf.deb ...
Unpacking python-apt (1.1.0~beta5) ...
Processing triggers for install-info (6.3.0.dfsg.1-1+b1) ...
Processing triggers for man-db (2.7.6.1-2) ...
Setting up dirmngr (2.1.18-8~deb9u4) ...
Setting up python-apt (1.1.0~beta5) ...
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 processing package python-apt (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 python-apt
Run Code Online (Sandbox Code Playgroud)

任何线索这里出了什么问题以及如何解决它?

小智 9

您之前使用的是哪个 Python 版本?升级到 python 3.7 后我也遇到了问题,我无法启动终端或执行任何用 python 编写的应用程序,我不得不运行sudo update-alternatives --config python3命令然后选择以前的 python 替代方案,之后一切又回到了正常我可以安装。

显示安装前后的图像 显示安装前后的图像