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.

classification
Title: Windows py launcher default for shebang line is surprising
Type: Stage: resolved
Components: Windows Versions: Python 3.10
process
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 *
 -3.8-64
 -3.7-64
 -3.6-64
 -3.5-64
 -3.4-64
 -3.10-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 pep2html.py, 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:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\Git\cmd
C:\Program Files\nodejs\
C:\ProgramData\chocolatey\bin

C:\Program Files\Microsoft VS Code Insiders\bin
C:\Users\gvanrossum\AppData\Local\Programs\Python\Python310\Scripts\
C:\Users\gvanrossum\AppData\Local\Programs\Python\Python310\
C:\Users\gvanrossum\AppData\Local\Microsoft\WindowsApps

C:\Users\gvanrossum\AppData\Local\Programs\Microsoft VS Code Insiders\bin
C:\Users\gvanrossum\AppData\Roaming\npm
>>>
History
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