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.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
4ae1e1
  • 1,459
  • 1
  • 12
  • 15

5 Answers5

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
4ae1e1
  • 1,459
  • 1
  • 12
  • 15
  • @BenjaminKohl Glad it helped :) – 4ae1e1 Apr 24 '14 at 07:19
  • Wasn't /etc/alternatives/python symlinked to /usr/bin/python2.7? did something else has higher priority? – heemayl Jun 19 '15 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 '15 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 '15 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 '15 at 17:34
  • In my case this was not enough: I also had to tweak /usr/share/python/debian_defaults so that it matches the version /usr/bin/python points to. – Pietro Braione Jun 15 '17 at 08:58
  • In my case I wasn't using alternatives ("update-alternatives --get-selections" didn't show python). Python was also working happily with apparently good links for /usr/bin/python and python2. Simply remaking the link for /usr/bin/python was enough to allow the update to work. FWIW. My Ubuntu is on a VMware VM. – John Jefferies Jun 11 '18 at 10:32
21

this one is correct:

sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python
Vitaliy Kulikov
  • 349
  • 2
  • 7
  • 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 – TryTryAgain Oct 10 '16 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.

  • 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 01 '18 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. – opinion_no9 Sep 02 '18 at 21:21
  • Saw "If this doesn't work for you, then I guess you have a genuinely corrupted python install."? – 4ae1e1 Sep 02 '18 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 02 '18 at 23:34
  • Your comments are welcome. – opinion_no9 Sep 04 '18 at 09:21
  • 1
    True, it works on 18.10. Thanks. – Wings Sep 18 '18 at 13:01
  • Step 2 fixes the issue. Very bizarre given the default is Python3 now! – DaveStephens Apr 19 '19 at 16:11
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.

Jana
  • 181
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