Skip to content

Shebang of "/usr/bin/env/python3" prevents launcher from executing script on a fresh Windows 10 install #114412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BookWorm0 opened this issue Jan 22, 2024 · 4 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@BookWorm0
Copy link

BookWorm0 commented Jan 22, 2024

Bug report

Bug description:

hello.py:

#!/usr/bin/env python3

print('Hello') # never runs

hello_noshb.py:

print('Hello (no shebang)')

Here is a screenshot of the silent failure.
Command

Cause: python3.exe is a 0-byte stub file in %USERPROFILE%\AppData\Local\Microsoft\WindowsApps, which is in PATH. The PSF installer creates python.exe, but not python3.exe. (When python3 is typed directly into command prompt, this stub causes Store to be launched. It offers to install a Store App version of an obsolete release of python.)

Workaround: Delete the 0-byte stub so that py.exe doesn’t invoke it.

Proposed long-term fix: For a script with a "/usr/bin/env" shebang, py.exe should check size of program found in path and act as if a 0 byte .exe doesn’t exist.

Alternate fix: Installer could create a python3.exe in the installation directory.

Screenshot of Store offering:
ObsoleteStorePython

CPython versions tested on:

3.12

Operating systems tested on:

Windows

@BookWorm0 BookWorm0 added the type-bug An unexpected behavior, bug, or error label Jan 22, 2024
@terryjreedy
Copy link
Member

This is known ##100107 Currently, one should leave off or remove /env to avoid the path search that finds the stub.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2024
@zooba
Copy link
Member

zooba commented Jan 22, 2024

@BookWorm0 Did you really get sent to Python 3.7 by the stub? Or did you just search that for the screenshot.

It should be taking you to 3.12 regardless of version of Windows.

@BookWorm0
Copy link
Author

That screenshot is my own, and it is what came up when I typed “python3” into Command Prompt.

@BookWorm0
Copy link
Author

This is known ##100107 Currently, one should leave off or remove /env to avoid the path search that finds the stub.

Unfortunately, macOS has an almost obsolete version of python in /usr/bin/python3, so the shebang line with /usr/bin/env is necessary for cross-platform scripts:

bookworm@bookworm-mbp ~ % /usr/bin/python3 -V
Python 3.9.6
bookworm@bookworm-mbp ~ % type python3
python3 is /opt/homebrew/bin/python3

(homebrew installs python3 on macOS.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants