How to fix "python installation is corrupted"?

All we need is an easy explanation of the problem, so here it is.

I was upgrading from 13.10 to 14.04 (dev for now, stable in a few hours) using do-release-upgrade and encountered the following problem:

Can not upgrade 

Your python install is corrupted. Please fix the '/usr/bin/python' symlink.

I solved the problem after messing around a bit, so I’d like to share my solution here. Hope this could help someone.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

My problem turned out to be solely due to an altered /usr/bin/python symlink as suggested in the error message. I was using update-alternatives with /usr/bin/python so it was pointing to /etc/alternatives/python. Turned out that do-release-upgrade is really strict with this symlink and merely selecting python2.7 with update-alternatives isn’t enough, so I ended up forcing it to its original state:

sudo ln -sf /usr/bin/python2.7 /usr/bin/python

And that solved the problem.

If this doesn’t work for you, then I guess you have a genuinely corrupted python install. I’d suggest

sudo apt-get install --reinstall python

Method 2

this one is correct:

sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python

Method 3

In Ubuntu 18.10 there is still the same issue.

The /usr/bin/python is linked to an older version. Even later than 2.7 are available but this super-smart process is asking (in 18.10!) for P 2.7. So I gave it and it was accepted.

This solved it for me:

1) delete /usr/bin/python doing sudo rm /usr/bin/python

2) Create a new link sudo ln -sf /usr/bin/python2.7 /usr/bin/python

In 18.10 I could NOT use sudo update-alternatives --remove-all python or sudo apt-get install --reinstall python .

Works for me. Hope it helps you, too.

Method 4

For Ubuntu 19.04 the default python version is 3.7 . I got same error while upgrading to Ubuntu 19.10, and, the following helped:

sudo apt-get install --reinstall python3
sudo ln -sf /usr/bin/python3.7 /usr/bin/python3

In case you have very serious problems with your python package, the only way left is to force remove it, and then reinstall it:

sudo dpkg --remove --force-remove-reinstreq --force-depends python3
sudo apt-get -f install

Method 5

If you run into this regarding /usr/bin/python3 then:

sudo update-alternatives --remove-all python3
sudo ln -sf /usr/bin/python3.6 /usr/bin/python3

Make sure to symlink python3.6 and not 3.7. At least that was required when upgrading Ubuntu 18.10 to 19.04.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply