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.
Related videos on Youtube
Author by
user3371321
Updated on September 18, 2022Comments
-
user3371321 almost 2 years
Is there a particular reason on why
update-alternatives
is not working withPython
since ubuntu comes bundled with different versions? -
Oli about 10 yearsExactly. Python 2 and 3 aren't considered alternatives. They're completely different things.
-
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 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 aspython3
. I saw a note about this somewhere in a PEP or in Python mailing list (can't remember exactly what's the source). -
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 almost 5 yearsThis will break your system hard. DO NOT attempt this.
-
DrBeco almost 5 yearsMaybe 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 almost 5 yearsThat 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 almost 5 yearsAlso 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.
-
DrBeco almost 5 yearsSorry 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 almost 5 yearsAlso: 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 almost 5 yearsEven 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 almost 5 yearsAnd 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 almost 5 yearsI'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