-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Python launcher invoked with command "py" fails to start process #99442
Comments
This error causes a failure to build MSI installer between version 3.7 and 3.10. (Example of GitHub Actions build failure in my personal project). This is because WiX invokes |
Confirmed, I am seeing the same issue (see the linked rust issue report above).
|
In Lines 565 to 580 in 88385b8
A couple of issues in
|
… include a file extension (pythonGH-99542) (cherry picked from commit a220c6d) Co-authored-by: Steve Dower <[email protected]>
The fix appears to have addressed part of my issue, but I'm still getting the same error in a slightly different case. I haven't yet been able to reduce the test case to something smaller, but if I use the
then running
If I add some debugging prints, I can see that the command being run was |
Thanks for the quick extra test! This one looks like it's probably shebang parsing - can you include the whole output you get with PYLAUNCHER_DEBUG set? |
Oh, this is probably the deliberate change of behaviour to make shebang lines only search PATH if you use If it falls through to the default case, we don't let you search for arbitrary executables. It will only look adjacent to the script file. The old behaviour was never documented, and isn't safe (the new behaviour is only mildly safer, but at least you can scan for
|
|
It is, and I don't love it, but most other approaches for my use case have downsides. I will say that the old launcher went into a hard recursive loop on this, locking my machine with masses of processes. That's extremely bad, and avoiding that is definitely worthwhile. Obviously, from what I'm doing here, you can tell that I'd prefer
and I run it as The reason I'm doing this at all is that I'm using The problem is that I don't want to hard-code a path for the interpreter in the shebang line, and the only way to run Python that's guaranteed to be on PATH is via I'm not even sure who I should be asking for help with this. In isolation, the behaviour of both |
The new launcher resolves Does Alternatively, does On a related note, the launcher supports user-defined commands such as "py" in the |
All of those are great ideas, thanks! I'll give them a try when I have some free time. Overall, it does seem a bit non-obvious to find something that works, which is a shame, but I don't think there's an easy resolution for that. Long-term, we should ideally have a unified way of running Python on all platforms, but I doubt that will happen soon... |
Actually, I had a few moments. Just's implementation of But using |
Actually, it appears that the fix for this issue has broken that case 🙁 At this point, I'm frustrated by this whole thing. The new behaviour (treating the shebang as relative to the script location) is a change from the behaviour described in PEP 397:
which was (as far as I am aware) introduced without discussion, and which is not included in the "What's new in 3.11" documentation. If I'm wrong, please point me to the discussion of this new behaviour. It's quite possible that I would have approved the change if I'd been asked about it in advance, and I'm definitely not suggesting that the new behaviour is wrong as such - but I do think that we should have provided better support and information for people who might have been relying on the old behaviour. Now that this has already happened, I'm not sure what, if anything, should be done. My feeling is that an "after the fact" update to the what's new document, offering migration advice in the "Porting to 3.11" section for people who were using the old behaviour, is probably the best thing to do. But I'm open to other suggestions (although I'm not keen on "do nothing", as you might have guessed 🙂). |
Yeah, there were certainly no updates made to the PEP, and we based the changes on what was in the documentation (worth noting that the PEP has a number of inconsistencies in this area, and is also dated with respect to what's considered secure practices). The discussion unfortunately seems to be in #98732, hidden under resolved comments (one of the reasons I always disliked the plan of moving everything to GitHub, but I didn't do this on purpose ;) ). FWIW, I found this by looking at NEWS for "launcher" and going to the one that was pretty clearly about changing the shebang handling. I still think it's highly defensible to drop the CWD search, but happy to argue about dropping the PATH search for unqualified names. There are already fixes coming in 3.11.1 to get closer to old behaviour, so no harm in bringing back more. Let's do it on a new issue though.
My sincere apologies for this. I know it's hard to keep up with all the changes going on in all the different places, but it's equally hard to know whose opinion ought to be sought on every issue. It's also frustrating for me to find that every change I make frustrates someone else for not being consulted (you're not the first), even if the change was accidental ;) , but I'm not sure what the solution is other than to stop contributing. 🤷♂️ That would be a childish response, but so would be pinging everyone on every discussion and waiting for quorum before doing anything. I'm open to ideas, and happy to discuss offline (with Paul, that is, not any random person who happens by here). |
Is this still expected to work? I've got some old scripts that did this (and worked in the past), but don't seem to work on 3.11.8:
In this case the launcher seems to be resolving the shebang as if it's a relative path to some executable in the current working directory. |
If you explain your use case for using the shebang "!#py -3", I may be able to suggest an alternative. As is, the launcher tries to resolve "py" in the shebang relative to the script directory. It doesn't search the current working directory or To search |
Ah, so probably Anyway, searching for the error only really brought me here plus a couple of other tickets, but this one had a comment explicity suggesting that what I had should work as of quite recently. (Hopefully this comment is then enough to help others running into the same issue 😃). |
We probably need to add "py" as a special case that restarts the whole search process with a new command line but with shebangs disabled. The earlier fix corrected handling for unnecessary quotes, but may as well reopen to further add a special case for using |
Unfortunately, other people demanded that |
Note that if CMD or PowerShell is used instead of bash, then directly running a .py script will execute the associated command-line template for .py files, which is usually the "py.exe" launcher. If so, the launcher's implementation of "#!/usr/bin/env py" will search for "py.exe" in |
I just checked this using the MSYS2 version of bash and env. There's a snag. bash passes "py -3" as a single argument to "/usr/bin/env", which in turn requires the option "-S" to split this string into multiple command-line arguments. The launcher's implementation could support "#!/usr/bin/env -S", basically by just consuming the "-S", but currently it doesn't. |
There's a limit on how much POSIX emulation we want to support, and I think Any other paths not matching those templates can be added to the |
The launcher's "env" implementation falls back on a virtual "python[X[.Y[.exe]]]" command if the executable name can't be found on
"py[.exe] [-X[.Y]]" could be reserved as a virtual command like "python[.X[.Y[.exe]]]". Then handling "#!/usr/bin/env py [-X[.Y]]" could default to a virtual command if either "py" isn't found or if the launcher finds itself. |
And just for reference, the reason I'm using
That's a good point. So perhaps the logic (if finding itself in the shebang line) needs to be:
Or maybe the second case should merge the criteria and flag an error if there's a conflict - that is, if the user specifies |
But even Has anyone ever considered/suggested porting |
The logic you describe is basically what's already in place, though it's way more complicated because there are 4-5 different ways to set defaults. Shebangs show up somewhere in the middle. I'm keen to not make this any more complicated, which is why about the only logic I'd consider is detecting
Yes, there is also a Besides, one major difference is that it doesn't do shebangs at all, because it relies on the system to handle them. If you
It depends exactly which emulation you're in. Cygwin brings its own Python build, which should include a |
I prefer the current behavior, which ignores the shebang if the launcher is executed with a "-X[.Y][-32|-64]" or "-V:tag" command-line option.
Yes, there are issues for POSIX environments on Windows that have to be resolved manually. For Windows, with the shebang "#!/usr/bin/env python[X[.Y][-32|-64]][.exe]", if the launcher can't find the executable in
|
Whoops, yeah, that's a bug. But at the same time, the intent of this limited shebang support isn't to provide an equivalent to what POSIX shells provide. It is really only meant to be limited to a few options that are compatible with other OSs so that developers who want to be compatible between both are able to achieve it. I've chatted with Brett, who maintains the POSIX launcher, and he said that the shebang handling in that one is entirely limited to the same basic templates as on Windows in order to restrict Python version. Windows has to handle a few more features, but I'm pretty strongly leaning towards narrowing the scope back to what seems to have been the original intent: basic compatibility with POSIX shells. What this would mean is that any shebang that doesn't work on a typical/reasonable Linux system is out of scope, even on Windows, and is unsupported. It doesn't mean that any shebang that does work there will be supported, but that the intent of shebang parsing is primarily to infer the I'm not closing this immediately because I expect further discussion, and if/when some consensus is reached then it needs to be documented somewhere, but I'm no longer intending to change the behaviour in order to support |
I'm using Git for Windows (which I think is built on top of MSYS2). It apparently doesn't come with a /usr/bin/python by default. Personally for this use case, I'm not too fussed about Having said that, I'm not actually sure how/why my shebang was working with |
Git Bash for Windows is about the most useless version of Bash, unfortunately, simply because it doesn't come with the full environment around it. As I said, we try not to actively break it, but there's very little we can do to make it work. I suspect that when you So what likely happens is that the Probably the best fix here is for Get Bash to detect the Alternatively you could configure a command in Footnotes
|
Oof! Yeah that sounds plausible and would explain the behaviour. Switching to |
Bug report
When I invoke a python launcher of version 3.11.0 with
"py"
command, a python launcher fails to start process.Step to reproduce
Install python 3.11.0 with py launcher for all users.
Invoke
"py"
in command prompt.I expect to launch a python interpreter, but got a error as below
Debug output when enable PYLAUNCHER_DEBUG
I think this error seems to be similar to #95285. If I invoke
py
or"py.exe"
, a python interpreter starts well as I expected.In version 3.10.8, all of
"py"
,py
and"py.exe"
start a python interpreter correctly.Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: