Error in "sudo update-manager -d" while upgrading to Ubuntu 20.04

I can't upgrade to Ubuntu 20.04 from 18.04. When I run sudo update-manager -d, it shows an error. I am seeing this error after an interrupted Ubuntu upgrade.

sh@sh-Lff:~$ update-manager -d
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/UpdateManager/backend/InstallBackendAptdaemon.py", line 239, in _on_finished
    trans_failed=trans_failed)
  File "/usr/lib/python3/dist-packages/UpdateManager/backend/__init__.py", line 319, in _action_done
    self.window_main.duplicate_packages = self.get_deb2snap_dups()
  File "/usr/lib/python3/dist-packages/UpdateManager/backend/__init__.py", line 125, in get_deb2snap_dups
    if (deb in cache and cache[deb].is_installed):
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 350, in __contains__
    return self.__is_real_pkg(self._cache[key])
TypeError: Expected a string or a pair of strings

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/UpdateManager/backend/InstallBackendAptdaemon.py", line 246, in _on_finished
    error_string=error_string, error_desc=error_desc)
  File "/usr/lib/python3/dist-packages/UpdateManager/backend/__init__.py", line 319, in _action_done
    self.window_main.duplicate_packages = self.get_deb2snap_dups()
  File "/usr/lib/python3/dist-packages/UpdateManager/backend/__init__.py", line 125, in get_deb2snap_dups
    if (deb in cache and cache[deb].is_installed):
  File "/usr/lib/python3/dist-packages/apt/cache.py", line 350, in __contains__
    return self.__is_real_pkg(self._cache[key])
TypeError: Expected a string or a pair of strings

Steps followed:

sudo apt-get update
sudo apt-get upgrade
sudo update-manager -d

After running the commands my update progress was fine, but my battery died and system got shutdown, I did above steps again and started seeing the issue

I updated the default version using below command:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 20

After an update when I check the python version using python --version. I see Python 2.7.17.


Solution 1:

I ran into this problem and will share how I was able to solve it.

The problem stemmed from some ubuntu package that was blocking the full ubuntu package updates for 20.04. So when I ran:

sudo apt list --upgradable

it showed a big list of packages especially a list of python3 packages even though I had just upgraded (and thus nothing should be 'more' upgradeable).

One of them was a package 2to3 so I tried running

sudo apt install 2to3

which mentioned some packages that were blocking install. For me, it was mutter and python-gi -- I sudo apt removed those and promptly a bunch of packages updated.

After that I ran

sudo apt upgrade

and it upgraded a bunch of the 'held back' packages. THEN, I ran sudo update-manager and it was able to start running where it had died before -- it finally reported the package that was blocking upgrade (for me, postgresql-10-postgis-2 .4) so I sudo apt removed it.

THEN, running sudo update-manager allowed me to move forward and I was able to complete running the 'partial upgrade'. python --version finally reported.

This is likely not concise instruction on how to fix it or yourself, but hopefully it will help.