How to fix 'ModuleNotFoundError: No module named 'apt_pkg'?

前端 未结 4 1653
眼角桃花
眼角桃花 2021-02-05 10:11

I\'m running code sudo apt update and fetch error

ModuleNotFoundError: No module named \'apt_pkg\'.

Please, help me s

相关标签:
4条回答
  • 2021-02-05 10:28

    I had this issue, it was caused because I had installed python 3.6.9 with 3.5.2 (Ubuntu 16.04) I had also used sudo update-alternatives --config python3 to not use auto setting it back to auto solved the problem for me (and then giving 3.6.9 priority was the next step to get the newest version of python running by default) New user: I can't reply to other comments :(

    0 讨论(0)
  • 2021-02-05 10:34

    In my case the problem was due to upgrading python version from 3.6 to 3.8.

    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
    
    sudo update-alternatives --config python3
    

    Solved by:

    Settings back the python version to 3.6

    0 讨论(0)
  • 2021-02-05 10:40

    In my case, the problem was that I removed original /usr/bin/python3 symlink on Ubuntu 18.04 and replaced it with one pointing to python3.8. Problem disappeared when I restored the original pointing to python3.6

    My takeaway is: if you need custom version of some library or module, install it in an isolated environment, do not mess up with system settings. Otherwise you are at risk of breaking something which can be noticed only later when it's difficult to figure out what exactly is wrong.

    0 讨论(0)
  • 2021-02-05 10:42

    Just reinstalled python3-apt and the error disappeared

    sudo apt remove python3-apt
    

    restart and then install,

    sudo apt install python3-apt
    
    0 讨论(0)
提交回复
热议问题