ModuleNotFoundError: No module named 'apt_pkg' error
Solution 1:
Its very late but could be helpful for others.
/usr/lib/python3/dist-packages# sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
Solution 2:
There was a similar question on 2014 (Problem with update-manager: No module named 'apt_pkg' in Ubuntu 13.10, having installed Python 3.4 on /usr/local/lib). The solution worked for me.
sudo apt-get remove python3-apt
sudo apt-get install python3-apt
Solution 3:
If you updated with a NEW python (e.g. dist had 3.5 but you installed 3.7), then your /usr/bin/python3
points to a python that does not have apt_pkg
.
edit /usr/bin/add-apt-repository
it says
#! /usr/bin/python3
Then edit /usr/bin/add-apt-repository
to point to
#! /usr/bin/python3.5
(insert your distro python version 3.5 for 16.04 & 3.6 if 18.04)
Solution 4:
Create a symbolic link at apt_pkg.so
which references to file apt_pkg.cpython-35m-x86_64-linux-gnu.so
.
cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so