I want to upgrade from Ubuntu 16.04.5 LTS to 18.04, so ran sudo do-release-upgrade
.
After downloading and extracting bionic.tar.gz
I get:
Can not upgrade
Your python3 install is corrupted. Please fix the '/usr/bin/python3'
symlink.
I saw How to fix "python installation is corrupted"? and so I did sudo ln -sf /usr/bin/python3.6 /usr/bin/python3
thinking that it would be a similar problem. But that didn't work (still same error message).
I have a few python versions:
$ ls /usr/lib | grep python
python2.7
python3
python3.5
python3.6
$ update-alternatives --display python3
python3 - auto mode
link best version is /usr/bin/python3.6
link currently points to /usr/bin/python3.6
link python3 is /usr/bin/python3
/usr/bin/python3.5 - priority 1
/usr/bin/python3.6 - priority 2
How do I fix python3
?
I just ran into this problem on Pop!_OS 18.04, trying to upgrade to 18.10, and it turns out that the problem lay in the symlink for
/usr/bin/python
and not for/usr/bin/python3
. I had had/usr/bin/python3.6
configured as an alternative forpython
(notpython3
), and when I changed this, then I could rundo-release-upgrade
as expected.I wish the error message pointed to
python
and notpython3
.Before, with the problem:
I fixed it this way:
Also see this comment below which describes a more precise solution that also better explains what is going on and how to fix it.
You need to use the default Python 3 version for 16.04. That's 3.5, not 3.6. So run:
If that doesn't work, try reinstalling the
python3
package.By the way,
update-alternatives --display python3
should give youupdate-alternatives: error: no alternatives for python3
. Different versions of Python are not alternatives in Ubuntu.None of the answers here seem to explain how you can get to the solution yourself, so I took on a journey, in my case inspecting
do-release-upgrade
in KDE Neon on Ubuntu 18.04 LTS.First, I ran it with
tracefile -w
and discovered that the actual release-upgrade-scripts were downloaded into a/tmp/ubuntu-release-upgrader-xxxxxxxx
directory.Using
grep
in that directory, I found the error message inDistUpgradeController.py
:So I inspected the surrounding code, which used the function
_pythonSymlinkCheck
, jumped to that and discovered the root of the problem: The script expected the symlink/usr/bin/python3
to resolve to exactly/usr/bin/<debian_default_python>
:As visible from the script,
<debian_default_python>
is thedefault-version
key in theDEFAULT
section from/usr/share/python3/debian_defaults
:My link did point to
/usr/bin/python3.6
, but via an extra indirection fromupdate-alternatives
, which the script doesn't resolve:So in the end I also resorted to the nuclear option, but now with full knowledge of what was going on :)
I observed this error message on Windows 10 1903 running WSL Ubuntu when I wanted to upgrade from 16.04 LTS to 18.04 LTS.
After
do-release-upgrade
had failed, I switchedpython
alternatives to every choice offered byupdate-alternatives --config python
and ran the upgrade command again. That did not help.Then I checked the log file
/var/log/dist-upgrade/main.log
which contained the linesSo although the error message mentions python3, the issue is about python2.
The upgrade script checks for
/usr/bin/python
linking to/usr/bin/python2
, see the source code ofDistUpgrade/DistUpgradeController.py
here: ubuntu launchpadSo one solution is to completely remove python from the alternative system and add the link manually, as described in the most popular answer.
If you don't want to remove python from the alternative system, just change the link only for the time during the upgrade process:
This worked for me.
During the upgrade process, the link is automatically repaired. So when the upgrade is finished, it points to the python entry in the alternatives directory:
Edit: for thorough information, the issue might also appear if you upgrade from 18.04 LTS to 19.04 and the anwser applies to this situation, too.
Basically the solution to this problem consists of making
/usr/bin/python
point to the right version of Python your Ubuntu release expects (for instance, in 16.04 was Python2.7 and in 18.04 was Python3.6).If you have several versions of Python installed in your system, you might be using
update-alternatives
to manage them. It doesn't matter much your default alternative for Python is the right version your system expects (3.6 in Ubuntu 18.04), it won't work.The reason why this doesn't work is that, when using
update-alternatives
,/usr/bin/python3
points to/etc/alternatives/python3
, and it seems that's not exactly the same as making/usr/bin/python3
point to/usr/bin/python3.6
.That's why the solution to this problem often consists of stop managing your Python3 versions with
update-alternatives
and make/usr/bin/python3
point to the right version of Python3 your system expects.The following commands should work:
I just tried upgrading to jammy (22.04) and hit the same error. The error comes down to an incorrect symlink check in the upgrader package. I've submitted a bug report with a fix in here.
What you can do to work around the problem is have your
python3
link directly to the final executable (without the detour via/etc/alternatives/python3
):Here is the fix when I tried to upgrade my xenial 16.04 box to 18.04
otherwise, the ubuntu-release-upgrader will complain with messages like
The major log file is located at
and there the release updater complained. Also, the other file you may want to check out is actually in /tmp/ubuntu-release-upgrader/*