Skip to content
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

python3 shebang does not work with py.exe and venv on Windows #103679

Closed
oldium opened this issue Apr 22, 2023 · 6 comments
Closed

python3 shebang does not work with py.exe and venv on Windows #103679

oldium opened this issue Apr 22, 2023 · 6 comments
Labels
OS-windows type-bug An unexpected behavior, bug, or error

Comments

@oldium
Copy link

oldium commented Apr 22, 2023

Bug report

Have the following:

  1. py.exe set-up to start Python programs (with PATHEXT env var set to ...;.PY)
  2. venv environment with Python 3

Now running Python program with shebang #! /usr/bin/env python works fine, but #! /usr/bin/env python3 does not.

I am running the same script on Debian 11:

  1. Debian 11 has only python3 and python3.9 executables system-wide, so python shebang does not work, but python3 works.
  2. Debian 11 venv environment (used during development) has python, python3 and python3.9 executables, so both python and python3 shebangs work.
  3. Windows 11 has only python.exe under venv, so python3 shebang picks-up MS Store version and not the venv version, so it has wrong modules.

On Debian 11 the only usable shebang for all my use cases is python3, but that one does not work under Windows.

Current workaround is to make a copy on Windows in venv/Scripts/python.exe to venv/Scripts/python3.exe. Then the python3 shebang works fine.

Your environment

  • Debian 11 with Python 3.9
  • Windows 11 22H2
    • py.exe left by installation of previous Python MSI version after uninstalling Python (and intentionally keeping py.exe).
    • Python 3.11 installed via MS Store
@oldium oldium added the type-bug An unexpected behavior, bug, or error label Apr 22, 2023
@arhadthedev
Copy link
Member

arhadthedev commented Apr 22, 2023

@oldium
Copy link
Author

oldium commented Apr 22, 2023

😢

@eryksun
Copy link
Contributor

eryksun commented Apr 22, 2023

At least the new py launcher that's included with Python 3.11 supports searching PATH for "python3.exe" when handling the shebang "#!/usr/bin/env python3". It's just a matter of making "python3.exe" available in virtual environments, which can be implemented by a symlink, hardlink, or copy.

The launcher could also implement "#!/usr/bin/env python[3]" to prefer an active virtual environment over searching PATH. That diverges from the behavior of "/usr/bin/env" on POSIX, but on the plus side it's retroactive for previous versions instead of depending on new venv behavior in Python 3.12+.

@zooba
Copy link
Member

zooba commented Feb 1, 2024

I believe this was fixed as #83180/#108101. Feel free to reopen if those didn't address this issue.

@zooba zooba closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
@oldium
Copy link
Author

oldium commented Feb 1, 2024

Thanks, I will test this with 3.13 release, then.

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

4 participants