|
|
Subscribe / Log in / New account

Linux distributions and Python 2

Linux distributions and Python 2

Posted Jun 12, 2018 1:10 UTC (Tue) by Kamilion (guest, #42576)
Parent article: Linux distributions and Python 2

I am struck that nobody seems to notice that the python2/3 problem was already solved on windows by providing py.exe as a frontend to any installed python version.

Shouldn't /usr/bin/python simply be treated the same way, and converted into a tool that will select python2 or python3 as appropriate? Seems a lot simpler to get people to *just fix that* in a well-distributed python script *now* rather than going as far as forcing them to convert to python3 right away.


to post comments

Linux distributions and Python 2

Posted Jun 12, 2018 5:58 UTC (Tue) by k8to (guest, #15413) [Link] (4 responses)

How does it determine what is appropriate?

Linux distributions and Python 2

Posted Jun 12, 2018 14:53 UTC (Tue) by rbanffy (guest, #103898) [Link] (1 responses)

If the script is already compiled to a .pyc, you can probably find out which version of Python compiled it (I never tried that because, frankly, I'm very happy with having python and python3 on /usr/bin).

Linux distributions and Python 2

Posted Jun 12, 2018 15:24 UTC (Tue) by k8to (guest, #15413) [Link]

That's determining which python already ran it, not which python it needs.
I don't believe it's very decidable.

Linux distributions and Python 2

Posted Jun 14, 2018 5:19 UTC (Thu) by kenshoen (guest, #121595) [Link] (1 responses)

They look at shebang line. #!python2 to 2, #!python3 to 3, #!python defaults to 2 (configurable).
https://docs.python.org/3/using/windows.html#customizing-...

Linux distributions and Python 2

Posted Jun 15, 2018 6:47 UTC (Fri) by nirbheek (subscriber, #54111) [Link]

So the same as Linux then?

py.exe on Windows solves a completely different issue: where is Python installed and how do I invoke it? All pythons (2, 3.4, 3.5, etc) are called python.exe, so putting it in PATH is not an option.

Linux distributions and Python 2

Posted Jun 14, 2018 6:18 UTC (Thu) by lambda (subscriber, #40735) [Link] (1 responses)

Which interpreter is the right one to use for the following code in an executable file named polyglot:

#!/usr/bin/python

print("2/3 = {}".format(2/3))

Will the output remain the same if one system decides to run it with a Python 2 interpreter and another runs it with a Python 3 interpreter?

Linux distributions and Python 2

Posted Oct 2, 2018 9:09 UTC (Tue) by cclauss (guest, #127609) [Link]

Adding from __future__ import division will print a fractional result in both Python 2 and Python 3.

Changing / --> // will print zero in both Python 2 and Python 3.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds