[Python-Dev] Clarification of PEP 394 for scripts that run under Python 2 and 3
Barry Warsaw
barry at python.org
Fri Nov 13 17:57:27 EST 2015
On Nov 13, 2015, at 10:32 PM, Damien George wrote:
>1. What is the true intent of PEP 394 when only Python 3 is installed? Is
>"python" available or not to run scripts compatible with 2.x and 3.x?
>
>2. Is it possible to write a shebang line that supports all variations of
>Python installations on *nix machines?
>
>3. If the answer to 2 is no, then what is the recommended way to support
>all Python installations with one standalone script?
It's important to remember that PEP 394 is an informational PEP, still under
active (if dormant) discussion. It is also just a recommendation, and can't
force any downstream redistributors to do one thing or another. Still, the
intent is to provide a set of guidelines for the majority of *nix distributors
to (eventually) adopt.
I'll also point you to the recently created linux-sig where this topic is
being discussed.
https://mail.python.org/pipermail/linux-sig/2015-October/000000.html
As you've noticed, Arch took a particular approach, but speaking as part of
the Debian/Ubuntu community, don't expect that ecosystem to go down the same
path. It's highly unlikely /usr/bin/python will ever point to anything other
than Python 2, even when only Python 3 is installed by default. That might
change once Python 2.7 is actually EOL'd, and that won't happen for quite a
long time. PEP 373 currently says there will be bug fix releases until 2020,
and I'd expect security-only releases for some time after that.
In general, the discussions on linux-sig and elsewhere is coalescing around a
launcher-type approach, where you'd put something like /usr/bin/py in your
shebang if your script really is bilingual. Then `py` can try to figure out
what's available on your system, what your preference is, etc. and then
execute your script using that version-specific binary. I would expect the
launcher to eventually be provided by the upstream Python development
community.
AFAIK, there have been a few stabs at writing such a launcher, but nothing
that's far enough to be usable.
So for now, you don't have great options.
Cheers,
-Barry
More information about the Python-Dev
mailing list