26

Here is the specific problem:

The following packages have unmet dependencies:
 libpython3.10-stdlib : Depends: libpython3.10-minimal (= 3.10.4-1+focal1) but it is not going to be installed
 python3.10-minimal : Depends: libpython3.10-minimal (= 3.10.4-1+focal2) but it is not going to be installed
                      Recommends: python3.10 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

Which package should I purge or reinstall? The system doesn't allow to do neither autoremove, fix broken, dist-upgrade?

Kubuntu 20.04 LTS

karel
  • 122,292
  • 133
  • 301
  • 332

4 Answers4

51

Edit: To summarize, I purged the packages and installed python3.10 as a new package. According to others who followed this, you do not need to remove and add the ppa as I did. I am removing that from the answer. It has also been suggested that merely forcing the install with sudo apt install -yf has worked when this issue came up in past versions. I can't verify because I did the following instead:

I had installed Python 3.10 using deadsnakes.

The issue and solution are described here:
libpython3.10-minimal and libpython3.10-stdlib fail to install #207

I ran the suggested command (explained in more detail at the end of this answer):
sudo apt --fix-missing purge $(dpkg -l | grep 'python3\.1[01]' | awk '{print $2}')

This prompted with:

The following packages will be REMOVED: idle-python3.10* libpython3.10-minimal* libpython3.10-stdlib*
libpython3.10-testsuite* python3.10* python3.10-distutils*
python3.10-examples* python3.10-full* python3.10-gdbm* python3.10-lib2to3* python3.10-minimal* python3.10-tk* python3.10-venv*

Note that there may be other packages removed with this command.

As suggested, I ran:
sudo apt --fix-broken install

There wasn't anything to fix because it had been purged.

Next I went ahead and upgraded unrelated packages before continuing:
sudo apt upgrade

At this point, running python --version showed it had rolled back to Python 3.8.10. I want Python 3.10 again so I ran:
sudo apt install python3.10

This prompted with:

The following additional packages will be installed:
libpython3.10-minimal libpython3.10-stdlib python3.10-minimal Suggested packages: python3.10-venv The following NEW packages will be installed: libpython3.10-minimal libpython3.10-stdlib python3.10 python3.10-minimal

The new install was a success!


Explanation For Cautious Beginners

The command used for purging python3.10 packages was:
sudo apt --fix-missing purge $(dpkg -l | grep 'python3\.1[01]' | awk '{print $2}')

The description of --fix-missing is found in man -apt-get:

Ignore missing packages; if packages cannot be retrieved or fail the integrity check after retrieval (corrupted package files), hold back those packages and handle the result. Use of this option together with -f may produce an error in some situations. If a package is selected for installation (particularly if it is mentioned on the command line) and it could not be downloaded then it will be silently held back.

purge:

purge is identical to remove except that packages are removed and purged (any configuration files are deleted too).

For the package names, a command substitution is used.

dpkg -l package-name-pattern...:

List packages matching given pattern.

Because no pattern was given for dpkg, a list of all installed packages is returned. In lieu of a pattern, the list is piped into grep so we can used the pattern 'python3\.1[01]' to narrow the list down to installed python3.10 packages. These results are then piped into awk '{print $2}'.

awk '{print $2}':

To put it simply, this awk a pattern scanning command. Here it returns only the package name from each line in the list. To better understand, run these commands together and observe the output:

dpkg -l | grep 'python3\.1[01]' | awk '{print $2}'

This should output a list of all of installed python3.10 package names, such as:

libpython3.10-minimal:amd64
libpython3.10-stdlib:amd64
python3.10
python3.10-distutils
python3.10-lib2to3
python3.10-minimal
python3.10-venv

The end result is the same as if you had entered all python3.10 packages yourself:

sudo apt --fix-missing purge libpython3.10-minimal:amd64 libpython3.10-stdlib:amd64 python3.10 python3.10-distutils python3.10-lib2to3 python3.10-minimal python3.10-venv

Now the system should be ready for a new install of python3.10.

iyrin
  • 1,439
6

This is how I fixed it for me:

$ sudo dpkg --force-depends --purge libpython3.10-stdlib

You will get a warning - ignore. Next:

$ sudo apt --fix-broken install

Finally:

$ sudo apt update
Peter
  • 61
  • 1
0

The following worked for me:

sudo dpkg -i --force-overwrite /var/cache/apt/archives/libpython3.10-*
0
sudo dpkg --force-depends --purge libpython3.10-stdlib

This code really break python3 in my ubuntu. It's already broken due to upgrade from 20.04 to 22.04 with maybe more than one python3 repository. I got python3.10.15-1+focal1 with no way to downgrade it to the real python3 version for 22.04.

Since it's already broken, I go ahead downloading all necessary the .deb of python3 in python3.10 3.10.12-1~22.04.6 source package, Ubuntu

I end-up force installing lot of it by using command

sudo dpkg --force-all -i ./example.deb

This is all the packages I use, replacing all python3.10.15-1+focal1 packages

python3-distutils_3.10.8-1~22.04_all.deb
libpython3.10-stdlib_3.10.12-1~22.04.6_amd64.deb  
libpython3.10_3.10.12-1~22.04.6_amd64.deb
libpython3.10-dev_3.10.12-1~22.04.6_amd64.deb 
python3.10_3.10.12-1~22.04.6_amd64.deb 
libmpdec3_2.5.1-2build2_amd64.deb 
python3.10_3.10.12-1~22.04.6_amd64.deb 
python3.10-minimal_3.10.12-1~22.04.6_amd64.deb 
python3.10-dev_3.10.12-1~22.04.6_amd64.deb 
python3.10-venv_3.10.12-1~22.04.6_amd64.deb

Everytime I finish force-install a python3 package, I run either this command to check what python3.10.15-1+focal1 packages left that is need to be replaced

sudo apt --fix-broken install
sudo apt upgrade
sudo apt install -f --reinstall python3
sudo apt install something_required_python3 (inkscape in my case)

Finally, when there is no more broken package, I end up successfully doing apt upgrade. Also, don't forget to clean repository in /etc/apt/sources.list.

So I hope this is helpful for anyone has python3 broken package in Ubuntu 22.04.