46

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.

5 Answers 5

63

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
7
  • @BenjaminKohl Glad it helped :)
    – 4ae1e1
    Apr 24, 2014 at 7:19
  • Wasn't /etc/alternatives/python symlinked to /usr/bin/python2.7? did something else has higher priority?
    – heemayl
    Jun 19, 2015 at 16:34
  • I am afraid you are getting it backwards..../usr/bin/python2.7 is the actual binary, it should never be the symlink, the symlink is the /etc/alternatives/python..do you mind checking it again?
    – heemayl
    Jun 19, 2015 at 17:31
  • @heemayl Sorry, misread your comment + typo on my part. /usr/bin/python is a symlink to /etc/alternatives/python (of course /usr/bin/python2.7 is the binary, but that's not the problem here).
    – 4ae1e1
    Jun 19, 2015 at 17:33
  • And yes, /etc/alternatives/python is then symlinked to whatever you selected (not necessarily /usr/bin/python2.7 — why would you even need update-alternatives in that case?), but the point is symlinking is not allowed for /usr/bin/python when you do-release-upgrade.
    – 4ae1e1
    Jun 19, 2015 at 17:34
21

this one is correct:

sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python
1
  • 2
    This is absolutely correct. It would not work for me until I also first removed all existing using the update-alternatives --remove-all python Oct 10, 2016 at 17:04
6

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.

7
  • 1
    ls -sf overrides the target so 1) is pointless, and 2) is exactly what my answer told you to do. What a waste...
    – 4ae1e1
    Sep 1, 2018 at 12:28
  • Dont rant: Your quote is wrong and I told the opposite of what you tell about "... --reinstall python". Yes, my experience with 18.10 is different than yours and I explain this. No need at all for brazen comments. Sep 2, 2018 at 21:21
  • Saw "If this doesn't work for you, then I guess you have a genuinely corrupted python install."?
    – 4ae1e1
    Sep 2, 2018 at 23:31
  • Basically, the lesson is: you read the surroundings and learn why, not just cherrypick whatever code blocks there are, paste them into your terminal (dangerous), and see what sticks. By the way, your sudo rm is still pointless.
    – 4ae1e1
    Sep 2, 2018 at 23:34
  • 1
    True, it works on 18.10. Thanks.
    – Wings
    Sep 18, 2018 at 13:01
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.

1
  • This was the solution for me since I manually forced the installation of python3 with external PPA May 27, 2023 at 12:52
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .