This isn’t an idea for Python as such, it’s a feature request for pip. If you want to see this, I suggest you raise it on the pip tracker. But it’s nowhere near as simple as you suggest:
- You need to cater for the zipapp build, so you can’t use
__file__
like this. - Just assuming that you can find
python
relative to pip is unlikely to work in general. - You can’t assume the Python executable is called
python
or is onPATH
. The Window launcher is an example where this won’t be the case. - There’s no guarantee the user has a
which
command - you should useshutil.which
.
So if you want this to go anywhere, you should create a PR that implements the functionality you want. Or if you just raise a feature request, I’ll copy this comment into it and mark the request as “awaiting PR”. But I doubt anyone else is likely to tackle it - we’ve had this issue/question for years, and no-one has been motivated to do anything about it (or if they have, they’ve failed).