Pip Installation /Usr/Local/Opt/Python/Bin/Python2.7: Bad Interpreter: No Such File or Directory

pip installation /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

I had used home-brew to install 2.7 on OS X 10.10 and the new install was missing the sym links. I ran

brew link --overwrite python

as mentioned in How to symlink python in Homebrew? and it solved the problem.

Error running pipenv, mkdocs : /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

Ah, think I've managed to fix it thanks to this thread: https://stackoverflow.com/a/54890849/201657 which suggested brew install python@2. It required me to install some xcode tools (xcode-select --install) as well:

$ brew install python@2
Error: Xcode alone is not sufficient on Mojave.
Install the Command Line Tools:
xcode-select --install

$ xcode-select --install
xcode-select: note: install requested for command line developer tools
$ brew install python@2
Updating Homebrew...
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics

==> Auto-updated Homebrew!
Updated 4 taps (moul/moul, homebrew/core, homebrew/cask and wagoodman/dive).
==> New Formulae
<snip>
==> Updated Formulae
<snip>
==> Renamed Formulae
<snip>
==> Deleted Formulae
<snip>

==> Installing dependencies for python@2: openssl@1.1, readline and sqlite
==> Installing python@2 dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/10/104ef018b7bb8fcc49f57e5a60359a28a02d480d85a959e6141394b0571cbb28?__gda__=exp=1579192531~hmac=4e0f24e7c23ef0b179b24e636e0648cf5ddacf1ba593c1eafb99df4abff27dd6&response-content-disposition=attachment%3Bfilename%3D%22openssl%401.1-1.1.1d.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX18FOL-sNoEItw923wfVaX0khFxEm_orjuu2BfyA4I5hITIsrm0IlATZztPdR
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1d.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.

If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> Summary
/usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing python@2 dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/3c/3c754391e9d243835811d128771ca0f1a565024100fd2c2871534353d46aaf0e?__gda__=exp=1579192567~hmac=484004e95b8e8bf6a1a3c3b93f2c499fedbc4aabefe7c7e69c441339c3576bc0&response-content-disposition=attachment%3Bfilename%3D%22readline-8.0.1.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX1-hB-7PyMBj4HiD3a21IEi6emuN13p6QaZTYdofdpr8PsmH2Wu3ZUE_qPFlc_K8yES
######################################################################## 100.0%
==> Pouring readline-8.0.1.mojave.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> Summary
/usr/local/Cellar/readline/8.0.1: 48 files, 1.5MB
==> Installing python@2 dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.30.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/5e/5e6fef2d754e0e4009d502c40ad1846ac46937886b5f3fe89378cb838626d95e?__gda__=exp=1579192572~hmac=a81364a3c7b176d89dceef369d52565faaafb7649a71270cbac0fe60cbc9c96e&response-content-disposition=attachment%3Bfilename%3D%22sqlite-3.30.1.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX1-c1S7wGXdJ_YZOPQaAbF12828yGxEYI4O4kHrFKyZT3yZn8p83BUHd5zcz957N2-IJ
######################################################################## 100.0%
==> Pouring sqlite-3.30.1.mojave.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.

If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"

For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"

==> Summary
/usr/local/Cellar/sqlite/3.30.1: 11 files, 3.9MB
==> Installing python@2
==> Downloading https://homebrew.bintray.com/bottles/python@2-2.7.17_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/54/54d3351d6be8268b2f5017894dcc8e083811dfa3812bdb9f79f989873b9a4542?__gda__=exp=1579192578~hmac=f79ee8bb690769cea6f7025f7266480dad73194bed15f36c005de20cd6cd38af&response-content-disposition=attachment%3Bfilename%3D%22python%402-2.7.17_1.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX18s65QivKoSQBP1QqsYGwHQyWAZXRxW-td799ewahemF_jTRodQsHVZ2ko4PZ
######################################################################## 100.0%
==> Pouring python@2-2.7.17_1.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/python
Target /usr/local/bin/python
already exists. You may want to remove it:
rm '/usr/local/bin/python'

To force the link and overwrite all conflicting files:
brew link --overwrite python@2

To list all files that would be deleted:
brew link --overwrite --dry-run python@2

Possible conflicting files are:
/usr/local/bin/python -> /usr/bin/python
==> /usr/local/Cellar/python@2/2.7.17_1/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python@2/2.7.17_1/bin --install-lib=/usr/local/lib/python2.7/site-packages
==> /usr/local/Cellar/python@2/2.7.17_1/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python@2/2.7.17_1/bin --install-lib=/usr/local/lib/python2.7/site-packages
==> /usr/local/Cellar/python@2/2.7.17_1/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python@2/2.7.17_1/bin --install-lib=/usr/local/lib/python2.7/site-packages
==> Caveats
Pip and setuptools have been installed. To update them
pip install --upgrade pip setuptools

You can install Python packages with
pip install <package>

They will install into the site-package directory
/usr/local/lib/python2.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
/usr/local/Cellar/python@2/2.7.17_1: 3,810 files, 51.3MB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.

If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> sqlite
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.

If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"

For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"

==> python@2
Pip and setuptools have been installed. To update them
pip install --upgrade pip setuptools

You can install Python packages with
pip install <package>

They will install into the site-package directory
/usr/local/lib/python2.7/site-packages

See: https://docs.brew.sh/Homebrew-and-Python

and now...

$ /usr/local/opt/python@2/bin/python2.7
Python 2.7.17 (default, Dec 23 2019, 21:25:34)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ ls -l /usr/local/opt/python@2/bin/python2.7
lrwxr-xr-x 1 jamiet DHDOM1\Domain Users 57 Oct 19 19:58 /usr/local/opt/python@2/bin/python2.7 -> ../Frameworks/Python.framework/Versions/2.7/bin/python2.7
$ pipenv
Usage: pipenv [OPTIONS] COMMAND [ARGS]...
$ mkdocs
Usage: mkdocs [OPTIONS] COMMAND [ARGS]...

yeay!

pip3: bad interpreter: No such file or directory

You've got a whole slew of different Python installations, plus at least one former Python installation that you deleted.

Situations like this are exactly why running pip or pip3 directly is no longer recommended, in favor of:

python3 -m pip install whatever

This guarantees that you're absolutely positively running the pip that goes with whatever python3 means, while pip3 just means you're running the pip that goes with some Python 3.x, which may be any of the various ones you've installed.

Or, even better, use virtual environments, so you can rely on the fact that python and pip are the commands from the currently-active environment, and not even worry about what they mean system-wide.


But, if you want to know how you got into this mess and how to fix it:

Your python3 command is probably from a Homebrew Python (you can check; ls -l /usr/local/bin/python3 and see if it's a symlink to something in /usr/local/Cellar/python).

Your pip3 command is from a Python 3 that doesn't exist. Most likely, you installed another Python 3, which overwrote the pip3 from the Homebrew Python 3, and then uninstalled it, leaving a broken pip behind.

The simplest thing to do is to just rm /usr/local/bin/pip3. Then, assuming you want your Homebrew Python to be your default for python3 and pip3, redo the brew link python command. If it shows you any warnings or errors, you still have other things to fix. If not, /usr/local/bin/pip3 should now be the Homebrew 3.6 pip, and which pip3 should pick out /usr/local/bin/pip3, and everything is good until the next time you install another Python 3 and overwrite a bunch of stuff.

A better fix would be to pick one way of installing Python—whether Anaconda, Homebrew, python.org installers, or whatever—and use that consistently. Uninstall everything, reinstall the one you actually want, and never touch the others again. (Unfortunately, you will still be stuck with Apple's system Python 2.7, but if you're only using 3.x, that won't matter.)

bash: /usr/local/bin/fab: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory

I found that my .bash_profile was not getting sourced.
So following was missing.

export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

For now I copied the contents of .bash_profile to .bashrc and things are working fine again

zsh: /usr/local/bin/youtube-dl: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory

  1. brew uninstall --ignore-dependencies python (you might not want to --ignore dependencies depending on what other things you might be breaking, i.e. numpy, opencv)

  2. brew install python@2 see here

  3. brew uninstall youtube-dl

  4. brew install youtube-dl



Related Topics



Leave a reply



Submit