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.exe launcher interacts badly with Windows store python.exe shim
Type: behavior Stage:
Components: Windows Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benspiller, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-05-19 17:20 by benspiller, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg369379 - (view) Author: Ben Spiller (benspiller) * Date: 2020-05-19 17:20
The py.exe launcher doc states "If no relevant options are set, the commands python and python2 will use the latest Python 2.x version installed" ... which was indeed working reliably until Microsoft added their weird python.exe shim (which either terminates with no output or brings up the Microsoft Store page) as part of https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/

Now, I find scripts that start with "#!/usr/bin/env python" cause py.exe to run the Windows python.exe shim which confusingly terminates with no output (unless run with no arguments). 

I think to stop lots of developers banging theirs heads against this brick wall, py.exe should include some logic to ignore the C:\Users\XXX\AppData\Local\Microsoft\WindowsApps\python.exe shim, since for someone with py.exe installed, running that is _never_ what you'd want. (or alternatively, work with Microsoft to get this decision reversed, but that may be harder!)

Lots of people are hitting this e.g. https://superuser.com/questions/1437590/typing-python-on-windows-10-version-1903-command-prompt-opens-microsoft-stor , https://stackoverflow.com/questions/57485491/python-python3-executes-in-command-prompt-but-does-not-run-correctly

Here's the output:

py myscript.py
launcher build: 32bit
launcher executable: Console
File 'C:\Users\XXX\AppData\Local\py.ini' non-existent
Using global configuration file 'C:\WINDOWS\py.ini'
Called with command line: apama-build\build.py   -h
maybe_handle_shebang: read 256 bytes
maybe_handle_shebang: BOM not found, using UTF-8
parse_shebang: found command: python
searching PATH for python executable
Python on path: C:\Users\XXX\AppData\Local\Microsoft\WindowsApps\python.exe
located python on PATH: C:\Users\XXX\AppData\Local\Microsoft\WindowsApps\python.exe
run_child: about to run 'C:\Users\XXX\AppData\Local\Microsoft\WindowsApps\python.exe myscript.py'
child process exit code: 9009

>py -0
Installed Pythons found by py Launcher for Windows
 -3.8-64 *
 -3.7-64
 -3.6-64
 -2.7-64

(nb: was surprising that it didn't run any of those installed versions!)
msg369380 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-05-19 17:44
If someone remembers where the other "shebangs on Windows don't make sense" issue is, I think we can close this one in favour of that.

Though it's also an important point for issue40667 - if "python.exe" becomes the launcher, then this will get stuck in an infinite loop (and process memory exhaustion is the worst kind of hang on Windows).
History
Date User Action Args
2022-04-11 14:59:31adminsetgithub: 84864
2020-05-19 17:44:01steve.dowersetmessages: + msg369380
versions: + Python 3.9, Python 3.10, - Python 3.6, Python 3.7
2020-05-19 17:21:07benspillersettype: behavior
2020-05-19 17:20:47benspillercreate