[Python-ideas] Make py.exe default to Python 3

Paul Moore p.f.moore at gmail.com
Wed Mar 9 04:47:28 EST 2016


On 9 March 2016 at 05:39, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Mar 9, 2016 at 4:32 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> If the proposal is to change the default behaviour for:
>>
>> * launching the interactive interpreter
>> * running scripts without a shebang line
>> * running scripts with an unrecognised shebang line
>>
>> then I think it's reasonable to switch all those to default to the
>> newest CPython runtime on the machine, regardless of whether that's
>> Python 2 or Python 3.
>>
>> However, if the proposal is also to change the handling of the
>> following shebang lines:
>>
>> * #!/usr/bin/python
>> * #!/usr/local/bin/python
>> * #!/usr/bin/env python
>> * #!python
>>
>> then I think those should continue to be handled in a manner
>> consistent with PEP 394 (and as PEP 397 currently specifies): as
>> referring to Python 2 (unless PY_PYTHON explicitly says otherwise or
>> only Python 3 is available).
>
> Agree with both of these points. AIUI the original proposal was solely
> about the first half, with no recommendation of change to the second.

My original post was prompted by interactive use, so I hadn't thought
of the #!/usr/bin/python case. I can see Nick's point here. But...

> What does py.exe do with a "#!/usr/bin/python" if the only Python
> installed is 3.5? Does it run it under 3.5, or error out?

I believe it runs Python 3. I no longer have a system with just Python
3 on, so I can't quickly test this, but I'd be surprised if it failed,
based on my experience. And Nick noted that using Python 3 if it's the
only one available is what the PEP says.

So with regard to changing the behaviour of shebang lines I see the
following points:

1. Compatibility with Unix, where an unadorned "python" in a shebang
means "python 2". I personally hate this behaviour, and view it as a
nasty wart of Unix. So I'm not in favour of promoting it on Windows
(IMO, if you're writing scripts for publication, be explicit about
whether you want Python 2 or 3 - an unqualified "python" in a shebang
line should be only for cases of "I don't care, my code works for
both" or purely personal code). But compatibility.
2. From what I recall of the py.exe code, implementing the exception
only for shebang lines would be more complex than the current code, so
I'd prefer there to be a demonstrated benefit. Unfortunately, it's
really hard to know how much the feature is used. I only use it myself
for personal scripts (and not much even then, tbh, because Powershell
is weird with file associations).
3. On Python 3 only systems, the current behaviour isn't consistent
with Unix anyway.

I don't disagree with limiting the change to not affect unversioned
shebang lines, but I'm not sure how much effort I'd personally be
willing to put into special-casing that. We can see on that one when I
start to look at the actual code, I guess...

Paul


More information about the Python-ideas mailing list