This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Python launcher behavior with "#!/usr/bin/env python" shebang
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
Status: closed Resolution: duplicate
Dependencies: Superseder: py.exe ignored PATH when using python3 shebang
View: 28686
Assigned To: Nosy List: Segev Finer, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-07-29 21:39 by Segev Finer, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg322645 - (view) Author: Segev Finer (Segev Finer) * Date: 2018-07-29 21:47
When using the common "#!/usr/bin/env python" shebang, recent versions of the Python launcher will search the PATH for "python" as specified in the shebang.

But Python on Windows installs as python.exe for all versions, both 2 and 3. So in a PC where Python 3 is first on PATH, this shebang will choose Python 3. That's in contrast to any other shebang like "#!python" or "#!/usr/bin/python" which will prefer Python 2.

That's rather subtle and confusing...

To the best of my knowledge most Linux distros still install Python 2 as python and Python 3 as python3 (I think that's in the Makefile too). But of course there might also be distros that install python3 as python.
msg322776 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-07-31 14:05
See the discussion in issue 28686 regarding the use of version detection and/or versioned executable names with env shebangs. I think the launcher should at least support searching PATH for pythonX.exe and pythonX.Y.exe, so users can at least manually copy or symlink to python.exe.
msg362897 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-02-28 18:29
This is not strictly a duplicate of issue28686, but it's close enough, so let's keep the discussion of changing the original shebang behaviour over on that issue.
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78455
2020-02-28 18:29:52steve.dowersetsuperseder: py.exe ignored PATH when using python3 shebang
2020-02-28 18:29:38steve.dowersetstatus: open -> closed
resolution: duplicate
messages: + msg362897

stage: resolved
2018-07-31 14:05:56eryksunsetnosy: + eryksun
messages: + msg322776
2018-07-29 21:47:19Segev Finersetmessages: + msg322645
title: Python launcher behavior with /usr/bin/env python shebang -> Python launcher behavior with "#!/usr/bin/env python" shebang
2018-07-29 21:39:57Segev Finercreate