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
108 Answers
Its very late but could be helpful for others.
> cd /usr/lib/python3/dist-packages
> sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so 3 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 7 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/python3Then 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)
2Create 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 1 The only thing that worked for me was to uninstall python 3.5 and then install the apt tools again:
sudo apt remove python3.5*
sudo apt install python3-apt
sudo apt install software-properties-common To solve this remove the alternatives
sudo update-alternatives --remove-all python3Then
sudo ln -sf /usr/bin/python3.6 /usr/bin/python3 The following worked for me. Firstly check the target apt_pkg library:
ls -l /usr/lib/python3/dist-packages/apt_pkg*it should return the following:
/usr/lib/python3/dist-packages/apt_pkg.cpython-35m-x86_64-linux-gnu.sowhere 35 stands for the python version. Set this version as default for python3:
sudo update-alternatives --set python3 /usr/bin/python3.5 This is the solution that worked for me for the latest apt_pkg_cpython package on Ubuntu18.04:
cd /usr/lib/python3/dist-packages/
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
sudo apt-get update