-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
py ./x.py
no longer works on Windows
#98650
Comments
py ./x.py
no longer works on Windows
@rustbot label C-bug |
Since this is also relevant, from the Using Python on Windows docs:
As much as MS would like to push the msstore version of python, the full installer is still generally preferred for developers. (Also, thanks, I used the blank template because I wasn't sure what to use for build tooling.) |
@rustbot label A-rustbuild |
While this is being shaken out in python/cpython#94399 (I agree with python/cpython#94399 (comment) — ideally this would be at most a warning, and Is there a different possible entrypoint with better availability across systems? python/cpython#94399 (comment) explains that |
From the discussion on the cpython issue it sounds like this is already fixed in the upcoming Python 3.11's We can decide whether to revert our x.py change until October. I am hesitant because it would involve re-breaking the Linux and macOS users, while Linux distributions (since 2020) and macOS upgrades (since October 2021) are deleting |
§ 4.8.4.1 Customization via INI files provides a workaround: [commands]
bash=python
I'm not 100% sure whether this is considered a feature or a bug in the new launcher at the moment, though, given the comment about not changing the old launcher's behavior, even though they said the no-
A different alternative would be to change the shebang to
Unless A list of maybe-potentially-useful-but-probably-not executables I spotted scrolling through:Yes this list includes pretty obviously non-useful commands. I picked basically anything with even a vaguely not-windows-specific name in System32.
Footnotes
|
I'm probably missing something obvious (I have basically 0 Python experience), but why can't we just document that Windows users do |
If you use the python.org installer with the default options then it won't add python to the path. That said, it is just a tick box to select it. |
Btw, I feel like I mentioned the failure mode in the OP on the original PR but perhaps I wasn't clear enough. |
This change broke existing workflows. Existing contributors aren't looking at documentation, and it seems weird to put the responsibility on them. |
I think this is an oversimplification; we regularly put responsibility on existing contributors. If an existing contributor's muscle-memory workflow breaks, most of them will not quit the project over it. They will look somewhere for guidance. The next step in this issue is figuring out where they look for guidance (probably directly in x.py, first), and putting guidance there. |
In general, I agree with this point and I'm also frustrated when my workflows are interrupted so I definitely empathize. We should absolutely strive to minimize workflow changes to project contributors! At the same time, it should probably be noted that at no point (from what I can see) have we ever told people to run Overall it's becoming increasingly clear to me that we need to move away from the current Python based system because of problems like this. @jyn514 had a fantastic idea there and I'm very excited to see that happen! Until that time though, we're very much stuck between a rock and a hard place. The reasons put forth in #98474 still seem compelling to me so I would prefer (speaking only for myself, personally) that we try to find a way to make the error message clearer as @jyn514 mentioned rather than reverting. |
Here's I think a near-full summary of the Windows behavior as it currently exists: Before (
|
Actually, I first blamed nushell 🙃 It was only after someone else prompted me that I checked in pwsh and realized the error was not coming from the shell and then went to check However, even though the contributing guidelines say to run At least to this Windows user, it seems the “more correct” behavior for Then ignoring the bootstrap problem entirely, it'd be nice for at least some directories to “just work” under the system/rustup Footnotes
|
Wouldn't it be easier to just add a separate |
I believe the possibility of |
In one of the other threads I commented on To this Windows user, it seems to make more sense to have an The actual broken workflows with a But why not make Maybe that logic doesn't hold, since "anyone" respecting the shebang "should" have (ba)sh available. (Caveat: win32 + The failure mode of IMHO, this makes it fairly clear that using a Footnotes
|
It's worth pointing out here that on Windows with WSL the 'failure mode' for |
That seems like a serious failure mode. I hadn't considered that. (Aside: I find it a bit weird that the python launcher will launch something that isn't python. But it is what it is.) |
Being explicit: the behavior is now tracked via a GitHub issue (python/cpython#94399). The seemingly most likely upstream classification is that
|
FWIW, as a contributor using Windows, that's what I've always done. I didn't know |
same for me, I often work on windows but use cygwin that doesn't have any problem with the change. |
Update on upstream: the new launcher has reimplemented the
If we want to avoid |
A summary of the current situation: #99992 changed the shebang from If you find that none of these options work for you, or the new situation is more inconvenient for you than before, please comment here or open a new issue :) |
As a procedural note, this should probably be unpinned in perhaps about a week if nobody reports an issue with the fix/mitigation/direction chosen. Ofc a new issue can always be opened after (or even before) that. |
Workaround for Windows developers
Put the following as
py.ini
in%LOCALAPPDATA%
:This will make
py
interpret the#!/usr/bin/env bash
shebang as runningpython
.You can also put
py.ini
alongsidepy.exe
. This is likelyC:\Windows
; you can find it withwhere py
cmd orGet-Command py
pwsh.Alternatively, run
x.py
withpy -3
to explicitly select to use the default Python 3 version rather than looking at the shebang. You should also be able to setftype Python.File="C:\Windows\py.exe" "-3" "%L" %*
so./x.py
will usepy -3
to run.To debug, set
$env:PYLAUNCH_DEBUG=1
pwsh/set PYLAUNCH_DEBUG=1
cmd.Issue description
#98474 added a
#!/usr/bin/env bash
shebang line tox.py
to allow./x.py
to work on unixy platforms withpython3
but notpython
(the previous shebang line was#!/usr/bin/env python
).This means that
x.py
no longer works on Windows machines which run python via thepy
Python Launcher for Windows, aspy
tries to interpret the shebang line (in order to use the correct python version) and ends up instead trying to run/usr/bin/env
, which obviously doesn't exist on a Windows machine. Explicitly asking for a specific version frompy
(e.g. by runningpy -3
for the latest 3.x version) will successfully run the script, as thenpy
ignores the shebang line.In theory this is an upstream bug;
py
should not be trying to run something that isn't python. In practice, though, this is how most Windows users will be launching python, as this is the launcher set up to handle.py
files when installing python from the official installer from the website orPython.Python.3
in winget. (The msstore python which the default-installedpython
andpython3
shims point to reportedly do not install thepy
launcher.) Additionally, this worked fine previously, and only broke with #98474.#71818 (comment) reports that
#!/usr/bin/env python
didn't work on Windows; I believe this is due to the order of events used in the described testing. @Walther first installed the msstore python. They then uninstalled the msstore python and installed the official python distribution, with "add python 3.10 to PATH" unchecked, reporting it to be unchecked by default. However, it was my experience that the official distribution did add python to the path by default; I suspect that the reason it didn't work for Walther was because (parts of) the msstore python was still in PATH, and the installer did not want to overwrite an existing installation. With my installation, apython
andpython3
shebang both work, and apython2
shebang results in a "Requested Python version (2) is not installed".Changing the shebang to
python3
has previously been delayed due to concerns about Windows compatibility. The specific situation seems to be this:py.exe
launcher (i.e. the shell uses theftype
registered handler), all python virtual commands will seamlessly work on Windows.python3
program, which most likely does not exist on a Windows machine. (E.g. in my winget install ofPython.Python.3
, I havepython.exe
andpython3.dll
in path, but nopython3.exe
.)The text was updated successfully, but these errors were encountered: