I run below command on ubuntu 16.4 :
sudo add-apt-repository ppa:noobslab/apps
of below question:
How to install PlayOnLinux on Ubuntu 16.04
and get below error:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
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 23, 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'
Original exception was:
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Thanks for help
Its very late but could be helpful for others.
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.
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 haveapt_pkg
.edit
/usr/bin/add-apt-repository
it saysThen 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)
Create a symbolic link at
apt_pkg.so
which references to fileapt_pkg.cpython-35m-x86_64-linux-gnu.so
.The only thing that worked for me was to uninstall python 3.5 and then install the apt tools again:
To solve this remove the alternatives
Then
This is the solution that worked for me for the latest
apt_pkg_cpython
package onUbuntu18.04
:The following worked for me. Firstly check the target
apt_pkg
library:it should return the following:
where
35
stands for thepython
version. Set this version as default forpython3
: