-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Shebang length exceeded in pip executable #1773
Comments
I hit this on some Jenkins jobs when the build name + params were long enough to create paths long enough trigger it. Thanks for the nice explanation. |
Another way is to run pip with |
Adding another +1 as a teammate hit this today as well. (Not sure on how to improve this, so will defer to others will better ideas :) |
@piotr-dobrogost thanks, edited original comment to say that explicitly. |
Yeah, but keep in mind you've got to call the right python when calling |
It's possible to write a wrapper for said shell script that will temporarily make the shebang max length longer. #!/bin/bash
script="$1"
shebang=$(head -1 "$script")
interp=( ${shebang#\#!} ) # use an array in case a argument is there too
# now run it
exec "${interp[@]}" "$script" The only other course of action would be to edit binfmts.h and recompile your kernel which is a bit silly. |
Within a virtualenv you could do these to patch the shebangs from bash.
Might be able to script this to apply to all python shebanged files in bin. |
Hit this issue recently and found this ticket, +1 for fixing it |
suggestion: instead of creating a |
As a word around you could create a hardlink from your nested job directory to |
Often /tmp/ is on a separate partition, so a hardlink will not work in that case. A symlink should work. From: Lars Schneider [mailto:notifications@github.com] As a word around you could create a hardlink from your nested job directory to /tmp/[randomid] and then work on there, no? — Spirent Communications e-mail confidentiality.This e-mail contains confidential and / or privileged information belonging to Spirent Communications plc, its affiliates and / or subsidiaries. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution and / or the taking of any action based upon reliance on the contents of this transmission is strictly forbidden. If you have received this message in error please notify the sender by return e-mail and delete it from your system. Spirent Communications plc Registered in England Number 470893 Or if within the US, Spirent Communications, |
Are there any plans on fixing this issue? I guess more and more people will hit this ugly bug. Pleaser remember that Jenkins is migrating to pipelines and that git flow generates really long branch names. This means that if you use git flow and trying to build all branches using Jenkins, you will reach this bug as soon you start to create the |
This is a limitation of the OS. The Linux kernel has a limit on how long a hashbang can be before it just stops reading them. |
This is a well known limitation and not a recently introduced bug with probable zero chances of being changes in the foreseeable future. This makes me think that @EricFalkenberg workaround could be implemented as the default behaviour of pip. For the moment we managed to avoid this by calling the modules directly but as we all know not all python applications are ready to be used like this. |
It's apparent this is a recurring issue and deserving of some kind of action. At the very least this scenario should be documented within the pip user guide as an alternative of using pip install in the cases where scripts' interpreters/hashbangs are too long. I've spent more time than reasonable stumbling around this problem just to run into this issue by happenstance. |
This is related to pypa/virtualenv#596 |
I am looking into submitting a patch to Linux to make the max shebang line a lot bigger. We'll see if the Linux devs accept it. The 128 char limit is ancient. |
While I have nothing against changing this limit you should be aware that even if is accepted on a fast track you will not expect it to reach 50% of the userbase in the next 5-10 years. People do not upgrade servers the same way they upgrade they iOS devices ;) |
@ssbarnea I am well aware of this, but I'm not terribly worried about the existing base (which has had to solve this problem one way or the other). The concern I have is forward looking. With all the automation being used today (often in a really sloppy way), shebangs longer than 128 are starting to be a problem. |
@tundratim Be sure you post links to the threads, I will do my best to support these changes. You are right that we will see more and more occurrences of this, and the use of virtual environments is probably the primary source for these. |
In Nix, we use following workaround to do the parsing in user space: https://github.com/shlevy/long-shebang |
Long term fixes and work arounds aside, is there any reason why this scenario shouldn't be explicitly documented in the pop user guide? Sent from my iPhone
|
@andyfeller No real reason, other than I'm not sure what we'd say (without making it sound like a much bigger issue than it is). Best approach would be for someone to raise a PR, and then we can thrash out the details there. FWIW, personally, I'd like to see it being clear that:
|
I wholeheartedly agree on all points. I just want to help others not waste time and get frustrated over a likely hurdle. Thanks! Sent from my iPhone
|
In virtualenv, creating your virtualenvs with the --relocatable flag helps with this issue, since part of what it does is change the shebangs to use The main issue with relocatable seems to be that it needs to be re-run every time you install a new package in the virtualenv. If pip/virtualenv could be modified so that --relocatable is more stable/ the default behavior, that might solve this (or at least the most common case.) |
got this problem on jenkins servers |
I also ran into this issue on Jenkins with virtualenv. Running pip as module does the trick: |
On 11/10/2016 05:41 PM, Rik Heijdens wrote:
Excellent tip, thanks. Tim Daneliuk tundra@tundraware.com |
FYI, in Spack we have since March been using a similar trick to what the #!/bin/bash /path/to/sbang
#!/long/path/to/real/interpreter with arguments
... rest of script ... This requires I'm not sure about the best way to apply this type of workaround to the The approach above would work, but it may not be so easy, considering |
This works around the shebang/virtualenv path length limit. See: pypa/pip#1773 Connects rcbops/u-suk-dev#1080
This works around the shebang/virtualenv path length limit. See: pypa/pip#1773 Connects rcbops/u-suk-dev#1080
This works around the shebang/virtualenv path length limit. See: pypa/pip#1773 Connects rcbops/u-suk-dev#1080
This is not just a Linux issue; Mac OS also imposes a limit of 512 characters. |
There are some possible work arounds, like using a redirector binstub or something of the sort. |
@dstufft Something along these lines? |
Yea. Not sure how that'd actually work out yet or if it would be acceptable fix but we should at least explore it first. |
As I noted above, we use distlib to write our wrappers, and hence it's an issue that should probably be fixed in distlib - in fact, I believe there have been some changes related to this in distlib. IMO, unless someone can find code in pip itself that writes out the shebang, this issue should be closed in favour of an issue on distlib (if the problem hasn't already been fixed there). However, I don't have the time at the moment to confirm this, I'm afraid. @dstufft do you know of a reason why this would be something to fix in pip rather than distlib? |
In
Last month this happened. This probably means pip just needs to switch to using |
Okay, that previous comment was preliminary. IIUC, pip doesn't write out the scripts on it's own, it does delegate that part to ScriptMaker. pip would just need to upgrade the vendored distlib, when it's released with the fix for long shebangs, which is already there in the master branch of distlib. @pfmoore Can this issue be closed or do we want to track the fix in distlib being released and vendored by keeping this issue open? |
IMO we can close this issue. |
Sometimes tox gate experiences issue [1] with the shebang length which is currently limited to the 127 symbols. As a workaround for that pip can be called as the python module with 'python -m pip [...]' RHOSINFRA-1475 [1] pypa/pip#1773 Change-Id: I9144c476341de1fc670dd5cead30f52cb6b274fc
On Linux, the pip executable is a shell script. At the top of this pip shell script is a shebang (#!) line that specifies the absolute path to the python interpreter.
If the absolute path to the python interpreter in the is very long (deeply nested and/or large path names), it may exceed the maximum length allowed for a shebang line. When the shebang length limit is exceeded, pip fails with the error: "bad interpreter: No such file or directory"
The maximum length for a shebang line is limited in the kernel by BINPRM_BUF_SIZE, set in /usr/include/linux/binfmts.h. On the Linux machines I looked at, this limit is set to 128.
A work-around for this problem is to not run pip directly, but run the python interpreter and pass the pip script to python as the source to execute, or run the pip library module (python -m pip).
It would be nice if pip was not affected by this limit. Usually this happens when creating a virtualenv with a long absolute path, but it could also happen with non-standard python installation path
The text was updated successfully, but these errors were encountered: