3 ms·
If you're living in limbo where "python" still means "python2", which isn't installed, as opposed to "python3", then this wouldn't work. Or theoretically also
by maweki 5y ago
If you're living in limbo where "python" still means "python2", which isn't installed, as opposed to "python3", then this wouldn't work.
Or theoretically also the other way around.
- talideon 5y agoIf you don't care which version of python it runs under, you do this: #!/usr/bin/env python If you do, then `python2` or `python3` will be around, and you should specify them explicitly instead of `python`. I'm happy to be corrected on this one, but I always slap this at the top of my scripts: #!/usr/bin/env python3 I'm not aware of anywhere that wouldn't invoke a Python 3 interpreter if one is installed. The original post just seems like one big faff.
- maweki 5y agoPEP 394 (which is now superseeded) clearly states that "python" shall invoke python2 and not python3 https://www.python.org/dev/peps/pep-0394/ https://www.python.org/dev/peps/pep-0394/ "The python command should always invoke Python 2 (to prevent hard-to-diagnose errors when Python 2 code is run on Python 3)." So there was indeed a time where the mentioned scenario was possible. Edit: love those people who got to downvote reality. At no point was python pointing to either 2 or 3 will-nilly, but there was always a PEP specifying best practice behaviour.
- remram 5y agoThe PEP is not superseded, still active. You got this quote from the "history of this PEP" section. This is not what the PEP currently mandates and it hasn't for 2.5 years: https://github.com/python/peps/pull/989 https://github.com/python/peps/pull/989
- maweki 5y agoThat was not the point. There was a time where the PEP specified that "python" means "python2" and it was indeed possible to have no "python" but still a Python (3) installation.
- eesmith 5y ago> "python" shall invoke python2 and not python3 The current version of PEP 394 says: ] If the python command is installed, it is expected to invoke either the same version of Python as the python3 command or as the python2 command. ] Distributors may choose to set the behavior of the python command as follows: python2, python3, not provide python command, allow python to be configurable by an end user or a system administrator. The part you quoted is from the section "History of this PEP". Just before your quoted text is: ] This PEP originally provided a very simple mechanism ... and just after it is: ] However, these recommendations implicitly assumed that Python 2 would always be available. This historic advice is no longer recommended. The change was made on July 5, 2019 - https://github.com/python/peps/commit/ae932bd6fd2c493d7d64ce328a5293bac4c48884#diff-3554a6100655720d1b8d5d8a03e2f71f04bfb840a1b6b500358972e53dce8e78 https://github.com/python/peps/commit/ae932bd6fd2c493d7d64ce... .
- remram 5y agoMy system doesn't have a `python`. On Ubuntu you need to install one of the `python-is-python2` or `python-is-python3` packages for the `python` command to be available. Command 'python' not found, did you mean: command 'python3' from deb python3 command 'python' from deb python-is-python3 https://packages.ubuntu.com/focal/python-is-python3 https://packages.ubuntu.com/focal/python-is-python3
- eikenberry 5y agoAll Debian based distros are this way, not just Ubuntu.
- remram 5y agoAnd a lot of non-Debian distros as well. Python 2 is officially retired after all.