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: Windows py launcher default for shebang line is surprising
Type: Stage: resolved
Components: Windows Versions: Python 3.10
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: gvanrossum, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-11-22 05:17 by gvanrossum, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg381590 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-11-22 05:17
I have 3.9 and 3.10 installed on my Windows box.

The py launcher runs Python 3.10 when invoked on a script starting with a shebang line

#!/usr/bin/env python

even though the default without a script is 3.9, as shown here:

PS C:\Users\gvanrossum\peps> py -0
Installed Pythons found by C:\WINDOWS\py.exe Launcher for Windows
 -3.9-64 *

PS C:\Users\gvanrossum\peps> py   
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

PS C:\Users\gvanrossum\peps> 

This caused some confusion since I was running a script that imported a package that I had installed in the default interpreter but not in 3.10.

I am not using a virtual environment (yet :-).

Without the shebang line the 3.9 interpreter is used.

(Full disclosure: the script was, and the package was docutils.)
msg381592 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-11-22 05:25
Oops, I think I understand why.  The py launcher actually does a search for an interpreter named "python" and that turns out to be python 3.10.

Now my question becomes why py chooses a different default than that.

I don't have a py.ini file in either of the two places mentioned by "py -h", nor do I have a PY_PYTHON env var.  Maybe it's because I installed 3.9 last?
msg381593 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-11-22 05:28
I guess this explains it:

>>> for p in os.getenv("PATH").split(os.pathsep): print(p)
C:\Program Files\Git\cmd
C:\Program Files\nodejs\

C:\Program Files\Microsoft VS Code Insiders\bin

C:\Users\gvanrossum\AppData\Local\Programs\Microsoft VS Code Insiders\bin
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86596
2020-11-22 05:28:15gvanrossumsetstatus: open -> closed
resolution: not a bug
messages: + msg381593

stage: needs patch -> resolved
2020-11-22 05:25:14gvanrossumsetmessages: + msg381592
2020-11-22 05:17:38gvanrossumcreate