Article 5Q5V3 No module named 'apt_pkg' when upgrading Ubuntu 16.04 to 18.04

No module named 'apt_pkg' when upgrading Ubuntu 16.04 to 18.04

by
bulgarianboy
from LinuxQuestions.org on (#5Q5V3)
I am new to Linux trying to upgrade from Ubuntu 16.04 to 18.04 using
Code:sudo do-release-upgradeBut I receive this error:

Code:Traceback (most recent call last):
File "/usr/bin/do-release-upgrade", line 11, in <module>
from UpdateManager.Core.MetaRelease import MetaReleaseCore
File "/usr/lib/python3/dist-packages/UpdateManager/Core/MetaRelease.py", line 25, 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'I have encountered this error in other places when trying to use apt.

I have tried this suggestion posted in lots of places:

Code:sudo apt-get install --reinstall python3-aptBut this does not solve the issue and I get the error:

Code:Reading package lists... Done
Building dependency tree
Reading state information... Done
0 to upgrade, 0 to newly install, 1 reinstalled, 0 to remove and 9 not to upgrade.
Need to get 0 B/145 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 302255 files and directories currently installed.)
Preparing to unpack .../python3-apt_1.1.0~beta1ubuntu0.16.04.12_amd64.deb ...
Unpacking python3-apt (1.1.0~beta1ubuntu0.16.04.12) over (1.1.0~beta1ubuntu0.16.04.12) ...
Setting up python3-apt (1.1.0~beta1ubuntu0.16.04.12) ...
/usr/lib/python3.8/subprocess.py:842: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
self.stdin = io.open(p2cwrite, 'wb', bufsize)System is Ubuntu 16.04 LTS running python as below:

Code:python -V
Python 3.5.2
python3 -V
Python 3.8.9

which python
/usr/bin/python
which python3
/usr/bin/python3Can anybody see why I cannot reinstall apt?

Let me know if you need any more info.latest?d=yIl2AUoC8zA latest?i=yQtYDtovb98:1rx1U0LH9WY:F7zBnMy latest?i=yQtYDtovb98:1rx1U0LH9WY:V_sGLiP latest?d=qj6IDK7rITs latest?i=yQtYDtovb98:1rx1U0LH9WY:gIN9vFwyQtYDtovb98
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments