UBUNTU No module named "apt_pkg" 錯誤修復。




$ 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

背景:
系統: ubuntu16.04

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'

...

試過好幾個方法都沒解決問題, 最終通過一開始羅列的那幾個步驟走完, 就沒再報這個錯誤了.



留言

這個網誌中的熱門文章

【多益】現點現做的英文怎麼說呢?

《Microsoft Word 應用》:圖片被文字蓋住解決方法,不可設定為固定行高

如何在Ubuntu系統上安裝Notepad ++ (Install Notepad++ On Ubuntu 16.04 / 17.10 / 18.04 / 20.04)