bad interpreter: No such file or directory


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=<NO_OF_CHARS>

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.

Have more questions?


  • 0
    Michael Lasevich

    While it is an explanation of the problem, it is playing fast and loose with definition of "Resolution".  Any ideas how to actually get around this - the workspace name alone in my case is over 60 characters long - and this is not counting the job name or branch name or parent path or any other bits that are required. 

Please sign in to leave a comment.