Score:1

apt-get upgrade does not work after updating python

br flag

I recently updated my python release from 3.8 to 3.10, using sudo update-alternatives --config python3, but this seems to have caused a problem with apt somewhere. Whenever I try to run sudo apt-get update it works as expected. When I then try to run sudo apt-get upgrade, I run into the following problem.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up python-apt (2.0.0ubuntu0.20.04.6) ...
/var/lib/dpkg/info/python-apt.postinst: 6: pycompile: not found
dpkg: error processing package python-apt (--configure):
 installed python-apt package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 python-apt
E: Sub-process /usr/bin/dpkg returned an error code (1)

When I try to reinstall python apt to fix this problem with sudo apt install --reinstall python-apt, I get the following error.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
E: Internal Error, No file name for python-apt:amd64

Does anyone know how I can fix this? I am also unable to open the software updater.

Score:13
us flag

This is expected. APT (and many other components of Ubuntu) requires a certain version of python to function properly.

To fix the issue, rollback the default python version with

sudo update-alternatives --config python3

To use python 3.10, simply use the command python3.10 (but do not link it against python3, which should be python3.8 in your case).

Alternatively, use virtual python environments.

Never change the default python version, as the system may be messed up so badly that in extreme cases, you will have to reinstall Ubuntu. This site is filled with tears of users who deleted/changed the default python version.

Note: You can use the Deadsnakes PPA to safely install multiple versions of python in LTS versions of Ubuntu.

iyrin avatar
de flag
I just want to reiterate for people using the deadsnakes PPA, run it with `python3.10` or use an alias that is not `python`. The reason it says `no alternatives for python3` is that deadsnakes is not installed as an alternative version to the one you installed in apt. It is a separate package. Don't change the symlink for the stable python3 install that is maintained by apt.
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.