Score:0

Stuck upgrading to ubuntu 20.04

us flag

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?

Raffa avatar
jp flag
Try fixing your system Python from a live system first ... See for example https://askubuntu.com/a/1448819
user535733 avatar
cn flag
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.
Joe Harrison avatar
us flag
@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 avatar
us flag
@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
us flag
Please consider writing your own solution as an answer
Joe Harrison avatar
us flag
@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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.