3

I am on mac (mojave osx 10.14) and admittedly I have a pretty messed up python environment.

Recently I have been getting multiple errors such as:

zsh: /usr/local/bin/pip: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory

zsh: /usr/local/bin/alembic: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory

zsh: /usr/local/bin/pytest: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory

This is the case even with creating and entering a virtualenv to work inside of.

In this specific case, I need a python3 virtual env.

When I which python outside the environment, I get /usr/local/bin/python and python -v = Python 2.7.15

Outside this virtualenv, I get these bad interpreter errors.

I create a virtualenv for python3 with virtualenv -p python3 .venv

Without even installing anything, I still get

zsh: /usr/local/bin/alembic: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory

zsh: /usr/local/bin/pytest: bad interpreter: /usr/local/opt/python/bin/python3.6: no such file or directory

If I pip uninstall alembic and pip3 uninstall alembic, I get the bad interpreter error still.

I have no idea where it might still be installed and not sure where to start on how to clean up my environment. Would like a fresh start but I don't know if that's possible.

Usman
  • 1,983
  • 15
  • 28
roy
  • 3,706
  • 6
  • 30
  • 53

2 Answers2

3

You have removed (uninstalled) /usr/local/opt/python/bin/python3.6 and the interpreter is used as the shebang in /usr/local/bin/alembic, /usr/local/bin/pytest and perhaps other scripts. The best way to fix them is to reinstall them with a different interpreter. For example:

/usr/bin/python3.6 -m pip install -U alembic pip pytest

/usr/bin/python3.6 is only an example here.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Yes, you're right, those files have that shebang. But, I thought if I'm working in a virtualenv, it would not be referencing those. Is there a proper way to do this to override what is in /usr/local/bin? If I specifically python3 -m pip install alembic... in the virtualenv it still gives me the same errors – roy Mar 19 '19 at 00:18
  • You have to install copies of these modules into the virtualenv. Then you use the scripts from `venv/bin/` instead of `/usr/local/bin/`. – phd Mar 19 '19 at 01:35
0

My problem (Mac OS 14.4.1) was with Python 2.7 version, which was missing symlinks. I've solved it by the problem by running:

brew link --overwrite python

As mentioned here

Adrian Onu
  • 671
  • 7
  • 13