Why I can't use update-alternatives to select Python 2 or 3?

6,801

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.

Share:
6,801

Related videos on Youtube

user3371321
Author by

user3371321

Updated on September 18, 2022

Comments

  • user3371321
    user3371321 almost 2 years

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

  • Oli
    Oli about 10 years
    Exactly. Python 2 and 3 aren't considered alternatives. They're completely different things.
  • RParker
    RParker about 10 years
    @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.
  • Hibou57
    Hibou57 almost 10 years
    @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).
  • enedil
    enedil almost 10 years
    @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.
  • Thomas Ward
    Thomas Ward almost 5 years
    This will break your system hard. DO NOT attempt this.
  • DrBeco
    DrBeco almost 5 years
    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.
  • Thomas Ward
    Thomas Ward almost 5 years
    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.
  • DrBeco
    DrBeco almost 5 years
    Also check: unix.stackexchange.com/questions/177899/… and gist.github.com/patrickmmartin/5b6b2ddecd29d6a1b2ffee2d8eea3‌​1ec 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.
  • DrBeco
    DrBeco almost 5 years
    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.
  • DrBeco
    DrBeco almost 5 years
    Also: in my answer, at the end, I added a note about "system breaking". So, to avoid these negative downvotes, I'll edit and move the note to the begin of the answer as a precaution.
  • Oli
    Oli almost 5 years
    Even if it doesn't break things on your system —per my comment half a decade ago on the accepted answer— Python 2 and 3 aren't alternatives. That's the only answer to this question. Yes, ofcourseyoucan train butterflies to write Python 4 with cosmic rays but that's not why there isn't an alternative for /usr/bin/python in Ubuntu. Alternatives are for drop-in replacements.
  • Oli
    Oli almost 5 years
    And regarding what doing this will break, run apt rdepends python | grep -vE ': python' | wc -l and you'll see the number of things the depend on Python 2, many expecting /usr/bin/python to accept a Python2 syntax. That's a count of 952 here on 19.04. This is just bad advice. Leave /usr/bin/python alone.
  • DrBeco
    DrBeco almost 5 years
    I've added an alternative solution with alias and a warning about the possible system break and how to revert. Thanks for the input. Again: I'm running a 5 years old server, upgraded to the last Debian buster and it doens't break, even running apache. The future is python 3. The apps that depend on python 2 are encouraged to use #!/usr/bin/env python2 instead of just python, and that will help in the transition. This answer may not be fully adequate today for some systems, but it is going to work during transition and it will be irrelevant in some years as python 3 assumes the default. Tks