更换python版本后出现 No module named "apt_pkg"

Posted 柒月

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了更换python版本后出现 No module named "apt_pkg"相关的知识,希望对你有一定的参考价值。

本文链接:https://blog.csdn.net/jaket5219999/article/details/78464310

$ sudo apt-get remove --purge python-apt
$ sudo apt-get install python-apt -f
$ sudo find / -name "apt_pkg.cpython-35m-x86_64-linux-gnu.so"
$ cd /usr/lib/python3/dist-packages/
$ sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.cpython-36m-x86_64-linux-gnu.so

背景:
系统: ubuntu17

python版本: 默认版本原来是python2.7,  先装了python3.5=python3.5.3 , 后又装了python3.6=python3.6.1

将默认版本改为python3.6后就出现No module named "apt_pkg"的问题了:

本来Ctrl+Alt+T是打开终端的快捷键, 突然用不了, 去到键盘里面的快捷键设置看到命令还是`gnome-terminal`

打开一个终端, 运行`gnome-terminal`就出现如下错误了:

...

Error in sys.excepthook:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named ‘apt_pkg‘

...

以上是关于更换python版本后出现 No module named "apt_pkg"的主要内容,如果未能解决你的问题,请参考以下文章

CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误

CentOS6.5 安装Python2.7后, yum出现“No module named yum”错误

解决安装Python版本出现No module named ‘apt_pkg‘问题

ModuleNotFoundError: No module named 'pymysql'

windows下使用Python出现No module named tkinter.ttk

no module named yum ?