0

When attempting to run pipenv & mkdocs on a mac I'm getting error:

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

$ pipenv
bash: /usr/local/bin/pipenv: /usr/local/opt/python@2/bin/python2.7: bad interpreter: No such file or directory
$ mkdocs
bash: /usr/local/bin/mkdocs: /usr/local/opt/python@2/bin/python2.7: bad interpreter: No such file or directory
$

Some additional information in case its useful, Command python links to what I think is the default python installation provided on a Mac:

$ which python
/usr/local/bin/python
$ ls -l $(which python)
lrwxr-xr-x 1 jamiet admin 15 Nov 12 12:58 /usr/local/bin/python -> /usr/bin/python
$ which python3
/usr/local/bin/python3
$ ls -l $(which python3)
lrwxr-xr-x 1 jamiet admin 34 May  2  2019 /usr/local/bin/python3 -> ../Cellar/python/3.7.3/bin/python3
$ python --version
Python 2.7.10

that may or may not be useful.

I found a useful thread where someone had experienced a similar issue: pip installation /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory and I've followed some of the suggestions on there:


brew link --overwrite python

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.

I believe python2 WAS initially installed on this machine using homebrew so I tried that, but no luck:

$ brew link --overwrite python
Warning: Already linked: /usr/local/Cellar/python/3.7.3
To relink: brew unlink python && brew link python

I have not (yet) tried the suggestion there (brew unlink python && brew link python) as I wanted to try a few other things and get some advice from here first


symlink to correct location

Tried to create a symlink to my known python2 interpreter at the location that pipenv/mkdocs are expecting it, but it didn't work:

$ /usr/local/bin/python --version
Python 2.7.10
$ ln -s /usr/local/bin/python /usr/local/opt/python@2/bin/python2.7
ln: failed to create symbolic link '/usr/local/opt/python@2/bin/python2.7': No such file or directory

Note that if I try a slightly different command (i.e. just a different path) then the command succeeds without error:

$ ln -s /usr/local/bin/python /usr/local/opt/python/bin/python2.7
$ ls -l /usr/local/opt/python/bin/python2.7
lrwxr-xr-x 1 jamiet admin 21 Jan 16 16:06 /usr/local/opt/python/bin/python2.7 -> /usr/local/bin/python

but that doesn't help me because pipenv/mkdocs are expecting the interpreter to be at /usr/local/opt/python@2/bin/python2.7 so I removed the symlink

$ rm /usr/local/opt/python/bin/python2.7

Can anyone suggest a way forward?

Community
  • 1
  • 1
jamiet
  • 10,501
  • 14
  • 80
  • 159

1 Answers1

0

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!

jamiet
  • 10,501
  • 14
  • 80
  • 159