Discussion:
Shebang lines for Python 3
Aaron Meurer
2011-09-04 19:07:35 UTC
Permalink
Hi.

We've been having a bit of a discussion about this on the SymPy
(sympy.org) issue tracker. Is it proper to use "python3" in the
shebang line of a script that should be run in Python 3? Something
like

#! /usr/bin/env python3

This shortcut works on my machine, but I don't know if it's universal
to all Python 3 installs. This certainly would make it easier to me
developing with those scripts, because I can just call ./script.py,
but I'm wondering if it's proper to use that in the final (Python 3
version of the) release of the package.

Aaron Meurer
Lennart Regebro
2011-09-05 05:32:56 UTC
Permalink
Post by Aaron Meurer
Hi.
We've been having a bit of a discussion about this on the SymPy
(sympy.org) issue tracker. Is it proper to use "python3" in the
shebang line of a script that should be run in Python 3? Something
like
#! /usr/bin/env python3
It is proper, sure.

This shortcut works on my machine, but I don't know if it's universal
Post by Aaron Meurer
to all Python 3 installs.
I know archlinux uses just "python" for Python 3 and "python2" for Python 2.
In general any install mechanism for your script should handle that, by for
example using distutils or something.

//Lennart
David Gowers (kampu)
2011-09-05 05:41:55 UTC
Permalink
Post by Lennart Regebro
Post by Aaron Meurer
Hi.
We've been having a bit of a discussion about this on the SymPy
(sympy.org) issue tracker. Is it proper to use "python3" in the
shebang line of a script that should be run in Python 3? Something
like
#! /usr/bin/env python3
It is proper, sure.
This shortcut works on my machine, but I don't know if it's universal
Post by Aaron Meurer
to all Python 3 installs.
I know archlinux uses just "python" for Python 3 and "python2" for Python 2.
Not that that stops you from using 'python3' or even 'python3.2' (though I
wouldn't recommend the latter.). So no changes should be necessary.
Lennart Regebro
2011-09-05 05:57:44 UTC
Permalink
Post by David Gowers (kampu)
Post by Lennart Regebro
Post by Aaron Meurer
Hi.
We've been having a bit of a discussion about this on the SymPy
(sympy.org) issue tracker. Is it proper to use "python3" in the
shebang line of a script that should be run in Python 3? Something
like
#! /usr/bin/env python3
It is proper, sure.
This shortcut works on my machine, but I don't know if it's universal
Post by Aaron Meurer
to all Python 3 installs.
I know archlinux uses just "python" for Python 3 and "python2" for Python 2.
Not that that stops you from using 'python3' or even 'python3.2' (though I
wouldn't recommend the latter.). So no changes should be necessary.
Right, "python3.2 " would be the best way here.
Eike Hein
2011-09-05 07:54:00 UTC
Permalink
Post by Aaron Meurer
This shortcut works on my machine, but I don't know if it's universal
to all Python 3 installs. This certainly would make it easier to me
developing with those scripts, because I can just call ./script.py,
but I'm wondering if it's proper to use that in the final (Python 3
version of the) release of the package.
I remember reading somewhere that it's currently the
recommendation of Python upstream to leave "python"
at Python 2.x - possibly even indefinitely - and use
"python3" for Python 3. Arch went against the grain
there, it seems.

I don't think "python3.2" makes sense unless you have
some reason to think it won't work with 3.3.
--
Best regards,
Eike Hein
Vladimir Perić
2011-09-05 09:42:23 UTC
Permalink
Post by Eike Hein
Post by Aaron Meurer
This shortcut works on my machine, but I don't know if it's universal
to all Python 3 installs.  This certainly would make it easier to me
developing with those scripts, because I can just call ./script.py,
but I'm wondering if it's proper to use that in the final (Python 3
version of the) release of the package.
I remember reading somewhere that it's currently the
recommendation of Python upstream to leave "python"
at Python 2.x - possibly even indefinitely - and use
"python3" for Python 3. Arch went against the grain
there, it seems.
If that's the case, would it make sense to have 2to3 automatically
convert these shebang lines? As a separate (perhaps not enabled by
default) fixer maybe?
Post by Eike Hein
I don't think "python3.2" makes sense unless you have
some reason to think it won't work with 3.3.
--
Best regards,
Eike Hein
_______________________________________________
Python-porting mailing list
http://mail.python.org/mailman/listinfo/python-porting
--
Vladimir Perić
Lennart Regebro
2011-09-05 10:10:43 UTC
Permalink
Post by Vladimir Perić
Post by Eike Hein
Post by Aaron Meurer
This shortcut works on my machine, but I don't know if it's universal
to all Python 3 installs. This certainly would make it easier to me
developing with those scripts, because I can just call ./script.py,
but I'm wondering if it's proper to use that in the final (Python 3
version of the) release of the package.
I remember reading somewhere that it's currently the
recommendation of Python upstream to leave "python"
at Python 2.x - possibly even indefinitely - and use
"python3" for Python 3. Arch went against the grain
there, it seems.
If that's the case, would it make sense to have 2to3 automatically
convert these shebang lines? As a separate (perhaps not enabled by
default) fixer maybe?
That's not possible as you don't know what they should be. And in any case,
the installer should adjust them (as distutils does, for example).

//Lennart
Aaron Meurer
2011-09-05 19:22:21 UTC
Permalink
OK, so actually Arch was the counterexample given in the other
discussion too. Does Arch not include a python3 alias? Is it safe to
say that Arch was really stupid for doing this, as it will break every
single Python 2 script that someone wants to use, so that we can just
ignore it?

And can someone point to relevant distutils documentation on how to do
this? I don't think that Vladimir's actually set up our setup.py
script yet to handle our Python 3 work.

Aaron Meurer
Post by Lennart Regebro
Post by Vladimir Perić
Post by Eike Hein
Post by Aaron Meurer
This shortcut works on my machine, but I don't know if it's universal
to all Python 3 installs.  This certainly would make it easier to me
developing with those scripts, because I can just call ./script.py,
but I'm wondering if it's proper to use that in the final (Python 3
version of the) release of the package.
I remember reading somewhere that it's currently the
recommendation of Python upstream to leave "python"
at Python 2.x - possibly even indefinitely - and use
"python3" for Python 3. Arch went against the grain
there, it seems.
If that's the case, would it make sense to have 2to3 automatically
convert these shebang lines? As a separate (perhaps not enabled by
default) fixer maybe?
That's not possible as you don't know what they should be. And in any case,
the installer should adjust them (as distutils does, for example).
//Lennart
_______________________________________________
Python-porting mailing list
http://mail.python.org/mailman/listinfo/python-porting
Lennart Regebro
2011-09-05 21:16:39 UTC
Permalink
Post by Aaron Meurer
OK, so actually Arch was the counterexample given in the other
discussion too. Does Arch not include a python3 alias?
They do.
Post by Aaron Meurer
Is it safe to say that Arch was really stupid for doing this
IMO, yes.
Aaron Meurer
2011-09-06 16:30:41 UTC
Permalink
Post by Lennart Regebro
Post by Aaron Meurer
OK, so actually Arch was the counterexample given in the other
discussion too.  Does Arch not include a python3 alias?
They do.
Ah, so the Arch argument really isn't a good one, because /usr/bin/env
python3 will still work there. And as far as I've heard, it will work
everywhere else too.

The real problem with Arch is that Python 2 stuff will break, not
Python 3, and as we decided, this is Arch's fault, not ours.

Aaron Meurer
Post by Lennart Regebro
Post by Aaron Meurer
 Is it safe to say that Arch was really stupid for doing this
IMO, yes.
Aaron DeVore
2011-09-06 23:33:44 UTC
Permalink
Post by Aaron Meurer
Ah, so the Arch argument really isn't a good one, because /usr/bin/env
python3 will still work there.  And as far as I've heard, it will work
everywhere else too.
The real problem with Arch is that Python 2 stuff will break, not
Python 3, and as we decided, this is Arch's fault, not ours.
Arch's justification was that switching /usr/bin/python would push
developers and library writers to port to Python 3. It mostly just
annoyed people, including me.

However, Arch brought up a valid point: Python developers should not
depend on "python" pointing to Python 2 for all eternity.
Distributions, users, or sysadmins may not want:

$ python

to point to an obsolete version. Shebangs are fine if setup.py uses
the scripts parameter to get shebang rewriting. Shebangs that require
a run of 'sed' are less ideal, but workable. Using:

subprocess.Popen(['python', 'script_name.py'])

is bad.

-Aaron DeVore
Barry Warsaw
2011-09-06 17:41:39 UTC
Permalink
Is it proper to use "python3" in the shebang line of a script that should be
run in Python 3?
Yes.

See PEP 394:

http://www.python.org/dev/peps/pep-0394/

While not yet approved, I think there's general consensus on the
recommendations in the PEP.

Cheers,
-Barry
Aaron Meurer
2011-09-07 00:32:30 UTC
Permalink
Excellent! That's exactly what I was looking for. It seems that
python2 is not very widely adopted (yet), but I think that python3 is,
and if anyone complains, we can point to this PEP/thread.

After this PEP is accepted (or even before), would the Python core
community consider adding a (potentially optional) fixer to 2to3 that
changes shebang lines?

Aaron Meurer
Post by Barry Warsaw
Is it proper to use "python3" in the shebang line of a script that should be
run in Python 3?
Yes.
http://www.python.org/dev/peps/pep-0394/
While not yet approved, I think there's general consensus on the
recommendations in the PEP.
Cheers,
-Barry
_______________________________________________
Python-porting mailing list
http://mail.python.org/mailman/listinfo/python-porting
Loading...