7

Is there a particular reason on why update-alternatives is not working with Python since ubuntu comes bundled with different versions?

14

The reason is, python versions aren't fully compatibile. If you set 3.3 version as your default, the applications made for 2.7 could not work.

  • 9
    Exactly. Python 2 and 3 aren't considered alternatives. They're completely different things. – Oli Apr 22 '14 at 10:28
  • 1
    @Oli Great... except that python 2.x automatically symlinks itself to /usr/bin/python, which IMO is the wrong behavior since they aren't alternatives. – Powerlord May 27 '14 at 18:29
  • 2
    @Powerlord, No, it's not a wrong behaviour, as python is intended to always mean Python 2 and Python 3 expected to always be referred to as python3. I saw a note about this somewhere in a PEP or in Python mailing list (can't remember exactly what's the source). – Hibou57 Aug 21 '14 at 10:29
  • @Hibou57 I think that in one or two years, they'll change meaning and python will be symbolic link to python3. That is in Arch Linux. – enedil Aug 21 '14 at 10:31
-4

Or maybe you can.

Important Note: The solution presented bellow (with update-alternatives) may break your system. If things break, try to fix them and keep python 3, report the fix you made to the correct bug-reports sites and help the community to grow; or move back to python 2. At the end of the answer I'll add a simple command to move back in case you need.

If you just want to change python for your own user, not the system, you can use an alias.

Solution 1: alias

Add this line into your ~/.bashrc or ~/.bash_aliases file:

alias python=python3

And that is it. You don't need to read bellow.

Solution 2: update-alternatives

If alias is not what you are looking for, and you really want to change the default of the whole system, then keep reading.

First check your python version:

# python -V
Python 2.7.13

Use this commands to install alternatives (run as root or use sudo)

# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
# update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

Then configure the version with (again, run also root or use sudo):

$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3.5   2         auto mode
  1            /usr/bin/python2.7   1         manual mode
  2            /usr/bin/python3.5   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

Now check the version:

# python -V
Python 3.5.3

When you run the above command, you can choose selection number: 0 or 2 to pick python 3. If things break, run again and pick number 1 to go back to python 2.


Good readings:

python3 statement

Hack-a-Day

The Register News

  • 2
    This will break your system hard. DO NOT attempt this. – Thomas Ward Sep 9 at 20:19
  • Maybe on ubuntu. As long term user of Debian and system admin, I'm experimenting with one of my systems for a month now and nothing breaks. I'll update if something goes wrong. – Dr Beco Sep 9 at 20:20
  • That breaks Debian too because not everything's undergone a Python 2 -> Python 3 conversion. Keep the Debian specific 'fixes' for this out of Ubuntu, because I can 100% guarantee you that doing this right now in Debian Unstable or in Ubuntu will *explode the system's ability to operate. – Thomas Ward Sep 9 at 20:21
  • Also check: unix.stackexchange.com/questions/177899/… and gist.github.com/patrickmmartin/5b6b2ddecd29d6a1b2ffee2d8eea31ec and of course about the apt break: stackoverflow.com/questions/43062608/… . No need to cause alarm, just discuss what will break instead of trying to add fear to people. – Dr Beco Sep 9 at 20:22
  • Sorry to disagree, but my current experiment (real server running 24/7 for a month now) is not broken. Maybe other packages that are not so necessary to my own system and are not installed breaks and I don't have them to check. Anyway, it is working fine. – Dr Beco Sep 9 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.