0

I've been trying to upgrade from Ubuntu 20.04 to 22.04. I'm trying to do this by running:

sudo do-release-upgrade

I'm met with the following:

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've removed and reinstalled python3-apt like here, but this doesn't do anything. I'm met with a similar error when even removing:

Removing ubuntu-advantage-tools (27.14.4~20.04) ...
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/usr/lib/python3/dist-packages/uaclient/apt.py", line 14, in <module>
    import apt  # type: ignore
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
dpkg: error processing package ubuntu-advantage-tools (--remove):
 installed ubuntu-advantage-tools package pre-removal script subprocess returned
 error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
 ubuntu-advantage-tools
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

From what I gather this could also be due to me having the wrong Python version (3.8). Using update-alternatives I've installed 3.6. But now when I run the python --version in the terminal I still see 3.8. I, unfortunately, can't remember what I've done. I might have made 'python' an alias, but I can't find where.

There is no alias for Python in ~/.bashrc

Can somebody make sense of the mess I've made? I'm happy to share additional information. How do I upgrade, and how do I downgrade to Python 3.6?

Joe Harrison
  • 61
  • 1
  • 2
  • Try fixing your system Python from a live system first ... See for example https://askubuntu.com/a/1448819 – Raffa Jun 16 '23 at 08:50
  • 1
    Ubuntu 18.04 = Python 3.6. Ubuntu 20.04 = Python 3.8. Changing to Python 3.6 was a mistake -- revert to Python 3.8. You must run do-release-upgrade in Ubuntu 20.04 using Python 3.8 plus all of its properly-versioned dependencies. – user535733 Jun 16 '23 at 12:54
  • 1
    @user535733 I think I've reverted back to python 3.8 now. python --version gives me 3.8.5 and I've also set the alternatives to python 3.8. Updating and upgrading goes fine. Installing update-manager-core too, but do-release-upgrade gives me the same problem: ModuleNotFoundError: No module named 'apt_pkg' – Joe Harrison Jun 16 '23 at 13:10
  • @user535733 I just checked what 'which python' gives and it points to /home/me/anaconda3/bin/python. This is not the system default. I'm now trying to revert to that first. Thanks for pointing me towards this – Joe Harrison Jun 16 '23 at 13:16
  • Please consider writing your own solution as an answer – Archisman Panigrahi Jun 16 '23 at 13:29
  • @archismanPanigrahi I don't have a solution yet. I've changed my bashrc file so the original python is used. which python now points to /usr/bin/python, but trying to install the new release still give me the same issue – Joe Harrison Jun 16 '23 at 13:32

0 Answers0