#StackBounty: #apt #package-management #upgrade #python No answer for ModuleNotFoundError: No module named 'apt_pkg' in Ubuntu …

Bounty: 50

I ran the following :

~$ sudo add-apt-repository "deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-8.0"

sudo: unable to resolve host root
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 12, 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'

To solve this I took numerous chances as said in askubuntu.com

sudo apt-get install python-apt
sudo: unable to resolve host root
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-apt is already the newest version (1.1.0~beta1ubuntu0.16.04.9).
The following packages were automatically installed and are no longer required:
  gksu libgksu2-0 pencil2d snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 393 not upgraded.


~$ sudo apt-get install python3-apt --reinstall
sudo: unable to resolve host root
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gksu libgksu2-0 pencil2d snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 393 not upgraded.
Need to get 0 B/147 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 208998 files and directories currently installed.)
Preparing to unpack .../python3-apt_1.1.0~beta1ubuntu0.16.04.9_i386.deb ...
Unpacking python3-apt (1.1.0~beta1ubuntu0.16.04.9) over (1.1.0~beta1ubuntu0.16.04.9) ...
Setting up python3-apt (1.1.0~beta1ubuntu0.16.04.9) ...


$ sudo ln -s apt_pkg.cpython-{35m,34m}-x86_64-linux-gnu.so
ln: failed to create symbolic link 'apt_pkg.cpython-34m-x86_64-linux-gnu.so': File exists


$ sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so
cp: cannot stat 'apt_pkg.cpython-36m-x86_64-linux-gnu.so': No such file or directory

$ sudo apt-get install --reinstall python3-apt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gksu libgksu2-0 pencil2d snapd-login-service
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 393 not upgraded.
Need to get 0 B/147 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 208998 files and directories currently installed.)
Preparing to unpack .../python3-apt_1.1.0~beta1ubuntu0.16.04.9_i386.deb ...
Unpacking python3-apt (1.1.0~beta1ubuntu0.16.04.9) over (1.1.0~beta1ubuntu0.16.04.9) ...
Setting up python3-apt (1.1.0~beta1ubuntu0.16.04.9) ...

$ sudo update-alternatives  --set python3  /usr/bin/python3.7

I tried each of these commands separately. Still I got :

$ sudo add-apt-repository "deb http://repo.mysql.com/apt/ubuntu/ xenial mysql-8.0"
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 12, 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'

To be frank I am fed up with this error and I’m sure that none of the above commands and commands given in other questions of askubuntu.com didn’t answer my need. As a last hope, I posted this question. Please Answer me.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.