-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #596
Comments
I am also experiencing this issue. |
Me too. |
Thanks for the workaround! |
Note that the wrapper scripts are actually generated by setuptools (if you install from sdist) or distlib (if you install from wheel). So any fix for this issue should really be requested from those projects. But if it's an OS limitation, maybe there simply isn't a viable fix? I seem to remember that at one time, Perl used a magic incantation to execute scripts (googles a bit...) Yes, something like this (translated for Python)
You'd need some extra stuff so that Python didn't try to execute the eval-exec line, but that might work. If anyone wanted to propose something like that as a feature request for setuptools and distlib, that'd be great. |
It would be really nice if running |
I'm hitting this also. It's specifically a problem for me as I'm running I like @b-long's suggestion; if |
It's not clear how virtualenv could detect this situation. We can't exactly use a value from a C header, and I don't know how we'd detect we're on a system with this limitation (Windows doesn't have it, does OSX?) I'm inclined to close this issue as an OS limitation, not a virtualenv problem. |
For what it's worth, some thoughts...
# on Linux, BINPRM_BUF_SIZE == 128, giving us a maximum shebang length of 127
# 2 bytes for #!, 11 bytes for '/bin/python' leaves us with 114
if sys.platform() == 'Linux' and len(home_dir) > 114:
log.warn("bin/activate may not work your system, as the length of the shebang line will exceed 128 characters") |
|
That being said, I think it's reasonable to assume that this won't be changing any time soon (there's a quick overview of the maximum shebang length here). The current length is also clearly given in the "Notes" section of the execve(2) man page, where it states, "A maximum line length of 127 characters is allowed for the first line in a #! executable shell script." I would assume that all POSIX-compliant operating systems have a limit of some sort, though it seems that some of them, specifically the BSD variants, may have limits upwards of 8,000 characters. While it seems like it would be a reasonable solution to simply hard-code something as naive as my above suggestion (if the platform is Linux and the line is longer than 127 characters), it feels overly crude and specific and inflexible to me. I'm still thinking about how I'd programmatically test this in a way that wouldn't add too much overhead to I have some simple proof-of-concept code to test whether or not a given path is an acceptable she-bang length, but it's rather ugly as it writes out a file to disk and then executes the file to capture the output. The example and output is here: https://gist.github.com/jantman/ba39f98936643bc948bd I'm going to have to call it a night, but I'll try to come back to this. I'd certainly appreciate the input of any other Linux users, or users of other OSes who can confirm whether or not they have a similar limit. |
Instead of trying to do something tricky like make assumptions about the limit, why not just make a functional test bash script? If python correctly gets invoked then everything is peachy, otherwise it isn't. |
To reiterate:
Closing this issue, as it isn't a virtualenv problem (you can get the same effect by installing a full Python interpreter to a long directory name).. |
Project: openstack-infra/project-config 3ae6ad913b838617593ca67b670b4af1c0708165 Shorten job names for OSA os_keystone repo Due to the length limit for the shabeng line [1] the jobs for the OpenStack-Ansible keystone role are failing. This patch shortens the names appropriately. [1] pypa/virtualenv#596 Change-Id: I11d39d786a01a5519e58752962e578169f667c7b
Due to the length limit for the shabeng line [1] the jobs for the OpenStack-Ansible keystone role are failing. This patch shortens the names appropriately. [1] pypa/virtualenv#596 Change-Id: I11d39d786a01a5519e58752962e578169f667c7b
Due to the length limit for the shabeng line [1] the execution of these tox targets in OpenStack-CI is failing (the full shebang length is 130 chars). This patch shortens the names appropriately. [1] pypa/virtualenv#596 Change-Id: I9011eac714e40d33baff7c1a1fc6eb0fdf47df55
Because we're otherwise hitting the upper limit for amount of characters and it makes tox unable to find the python things. pypa/virtualenv#596 Change-Id: Ic1e6b3a55c17f8a2ba41f29e63fc3f0bea5e5c49
We just hit this issue. Why not use the python from the PATH? virtualenv already prepends it with the bin dir.
|
Only if you activate the virtualenv. Virtualenv supports being used without activation. |
…/virtualenv#596) Change-Id: I7febfdf5573bda6cbd01a96ef4b7c0838f8ba477
…/virtualenv#596) Change-Id: I5194521dfab2e0be70660224c78b8b1711457ad7
…/virtualenv#596) Change-Id: I7e020e1684fbcd3cf49bfca2ccf6ecddf30d4276
…/virtualenv#596) Change-Id: Ib08b3b37ca23379cf7f6c89aa9b0c3f5b497dd8d
…/virtualenv#596) Change-Id: I48f9c7d30906ccdf2a0f8c8bcce4e032cb708df5
If anyone find this confusing:
That means instead of |
This file allows an easy invocation of websockify as a module, which is handy when running into shebang issues (pypa/virtualenv#596). With this patch, `python -m websockify ...` has just the same behavior as `./run ...`.
This file allows an easy invocation of websockify as a module, which is handy when running into shebang issues (pypa/virtualenv#596). With this patch, `python -m websockify ...` has just the same behavior as `./run ...`.
…rkaround described here: pypa/virtualenv#596
Sometimes artifact-metadata dir is located under long enouth path, and being mounted 'as is' it leads to tox failure. This is because pip (?) replaces shebang string in 'metadata-app' when installs it into virtualenv, and if the string is long enough we've got failure. There is github issue related: pypa/virtualenv#596 This commit mounts any external path to internal '/workspace' dir and fixes the issue. Related-Prod: PRODX-2782 Change-Id: Ie3405086a94a9f7315ce0ba935d1dd68a85d0325
This file allows an easy invocation of websockify as a module, which is handy when running into shebang issues (pypa/virtualenv#596). With this patch, `python -m websockify ...` has just the same behavior as `./run ...`.
When a new virtualenv is created, there are a number of things installed into that virtualenv. One of these things is the python package installer, pip.
On Linux, the pip executable is a shell script. At the top of this pip shell script is a shebang (#!) line that specifies the python interpreter in the virtualenv. This line contains the absolute path to the python interpreter.
If the absolute path to the python interpreter in the virtualenv is very long (deeply nested and/or large path names), it may exceed the maximum length allowed for a shebang line.
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.
So, when the path, to where a python virtualenv is created, becomes too long, using that virtualenv's pip will not work. It will fail with the error: "bad interpreter: No such file or directory"
A work-around for this problem is to not run pip directly, but by run the virtualenv's python interpreter and pass the pip script to python as the source to execute.
The text was updated successfully, but these errors were encountered: