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
Incorrect shebang generated by Pip when run as part of CPython build and installing to a DESTDIR #171
Comments
Ideas to solve:
Workarounds:
|
In pypa/pip#11237 I have come to the same conclusion, i.e. suspect ad0ea22 as introducing this problem. My repro was with Python 3.8.13 (bundles pip 22.0.4) and Python 3.10.5 (same pip) on Debian 10 and macOS 12.4. |
Not quite, because there is already a guard |
It's kind of a corner case. I think the ad0ea22 change exposed something that previously worked by chance - in this case, if none of the files exist at the time the shebang is computed, there's not enough information to make a determination as to whether a particular |
What does the shebang look like on your system if you do for example |
Well, the files surely exist at the correct place, if ensurepip would tell distlib where to look. I.e. it would need to pass down the |
Well, I guess in the end this means distlib should not do any guessing, and sysconfig should just know the interpreter binary name. ... |
Just as one would expect:
So if I were to put all these files into a package and install them into /, it would still not work. |
Indeed. The logic for ad0ea22 only kicks in if no executable is specified (the Lines 160 to 177 in ad0ea22
Thus I'm not sure this is actually an issue for |
I think both parts need changes. distlib needs a way that ensurepip can tell it about Smashing together the executable and |
I'm not suggesting that |
Ah, understood.
Well, how does ensurepip know what to put in there? |
Well, whatever the |
It seems like this should be dealt with by |
Describe the bug
Since CPython 3.9.11 / pip 22.0.4 / distlib 0.3.3, the
pip3
script generated at CPython install time has an incorrect shebang line.To Reproduce
Steps to reproduce the behavior:
In a CPython git clone:
Expected behavior
The shebang I see with CPython 3.9.11 / pip 22.0.4 / distlib 0.3.3 is:
#!/usr/local/bin/python
. This file does not exist.The shebang I see with CPython 3.9.8 / pip 21.2.4 / distlib 0.3.2 is:
#!/usr/local/bin/python3
. This file will exist, but it does not at the time the CPython install runs.Environment
Additional information
This issue is a little hard to track down, as it only reproduces during CPython build, where distlib is embedded inside the file
Lib/ensurepip/_bundled/pip-22.0.4-py3-none-any.whl
.I suspect that the regression was introduced in this commit: ad0ea22
This adds a line to ScriptMaker._get_shebang() which does the following:
In my scenario,
executable = /usr/local/bin/python3
. This file does not exist, because we ranDESTDIR=/tmp/destdir make install
and so the file has been installed to/tmp/destdir/usr/local/bin/python3
. However, this is the path that should be used in the script shebang line, and distlib <= 0.3.2 handled the situation correctly. The change introduced in distlib 0.3.3 incorrectly chooses/usr/local/bin/python
instead.The change is subtle, many OS distributors will create a symlink
bin/python3 -> bin/python
that hides the issue. In my case we do not have such a symlink, thus we get apip3
executable that fails to start with an error like:The text was updated successfully, but these errors were encountered: