Skip to content

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

@oldium

Description

@oldium

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions