Script containing a "shebang" would not start under Windows · Issue #100107 · python/cpython

The new launcher's "/usr/bin/env" virtual command searches PATH for the given command name, even if the command is "python" or "python3". The old launcher reserves these names.

If the command isn't found in PATH, the launcher ignores the shebang and runs the script normally. In this case, the GUI launcher, "pyw.exe", will execute the script using the default GUI binary (e.g. "pythonw.exe" from a registered installation).

Instead, a console window pops up and disappears instantly.

The launcher probably found the app execution alias "%LocalAppData%\Microsoft\WindowsApps\python3.exe". If the app version of Python 3 isn't installed, then by default Windows creates "python.exe" and "python3.exe" aliases for an "app installer" app that opens the store to install Python 3. If this app is passed any command-line arguments, it prints an informative message1 and exits. Since the app installer doesn't inherit a console from "pyw.exe", it allocates one to print the message. This console window gets destroyed as soon as the app exits2.

If you don't have the app distribution of Python installed, I recommend disabling the "python.exe" and "python3.exe" app execution aliases.

On double-clicking hello.pyw, a console opens, then the message box appears.

For the virtual command "/usr/bin/env python", the launcher searches PATH for "python.exe". Normally this binary is a console application, which means that the system automatically allocates a console for the process if it doesn't inherit one from the parent process.

The old launcher reserves names that start with "python", even for the "/usr/bin/env" virtual command. In this case, "pyw.exe" runs a registered version of the GUI (non-console) binary, "pythonw.exe".

  1. "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases."

  2. If the user's default console is Windows Terminal, it can be configured to keep a tab open after a console session has terminated. This allows the user to read and copy text from the terminal window after a console application has exited or crashed, even when the application is executed by a GUI process such as Explorer.