Skip to content

Shebang length exceeded in pip executable #596

@ajgillis

Description

@ajgillis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions