3

Using Ubuntu 16.04

Tried to set python 3.6 as default for the python3 command. I found what seemed to be the answer and quickly copy-pasted the following lines without carefully reading:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
update-alternatives: using /usr/bin/python3.6 to provide /usr/bin/python (python) in auto mode
$ sudo update-alternatives  --set python /usr/bin/python3.6

This is the result:

$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
$ python
Python 3.6.8 (default, Dec 24 2018, 19:24:27)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.python

A friend of mine tried to set it back like this:

$ sudo update-alternatives --install /usr/bin/python3.6 python /usr/bin/python 1
update-alternatives: renaming python link from /usr/bin/python to /usr/bin/python3.6

And this was the result:

$ python
zsh: command not found: python

And now anything linked with python 3.6 gets the error "Too many levels of symbolic links", like in this example:

$ sudo update-alternatives --config python
update-alternatives: warning: alternative /usr/bin/python (part of link group python) doesn't exist; removing from list of alternatives
update-alternatives: error: cannot stat file '/usr/bin/python3.6': Too many levels of symbolic links

The BIG problem is that if you close the terminal like like my friend did then the terminal app stops working all together. He now has to reinstall Ubuntu. And I am in the same situation, just that I still DID NOT CLOSE my terminal and (for now) everything works fine.

How can I reverse the symbolic links?

2 Answers 2

7

The Python packages don’t use alternatives; to restore a working setup:

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

You’ll probably have to re-install your Python 3.6 package since it appears you’ve overwritten the python3.6 binary.

3
  • Thank you ! I did have to reinstall python 3.6. All good now. Apr 13, 2019 at 8:54
  • @StephenKitt I have tried sudo update-alternatives --remove-all python3 ==> I get: update-alternatives: error: cannot stat file '/usr/bin/python3': Too many levels of symbolic links
    – Bilal
    Feb 25, 2023 at 6:40
  • 1
    @Bilal it sounds like your situation is different from that described in this question; please ask a new question with details of your specific problem. Feb 25, 2023 at 8:51
0

first unlink the broken one.

unlink /usr/bin/python2.7

then configure with sudo update-alternatives

sudo update-alternatives --config python

after that re-run your desired command

You must log in to answer this question.

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