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

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

在我的 Linux Raspbian 发行版上安装 Python 3.6.8 后,当我尝试安装 libunwind8 时出现错误:

ModuleNotFoundError: No module named 'apt_pkg'

调试后我发现以下 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

有什么线索可以知道这里出了什么问题以及如何解决吗?

答案1

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

安装前后对比图 安装前后对比图

相关内容