bad interpreter: No such file or directory

Article ID:360001980812
1 minute readKnowledge base


Executing pip commands in a virtual environment causes bad interpreter: No such file or directory


There are two causes of this:

  • The absolute path of the python interpreter exceeds the maximum length allowed by the OS

  • The absolute path is invalid due to spacing in the naming of Jenkins folders and / or jobs

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. By default, Linux machines has this limit is set to 128.

While this is an OS level limitation, there are some things that can be done Jenkins to reduce workspace character path lengths:

If the issue is specific to Multibranch projects then you can look at which advises how to limit workspace path lengths using system property jenkins.branch.WorkspaceLocatorImpl.PATH_MAX=

Another 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.