/usr/local/bin/pip: bad interpreter: /usr/local/opt/python/bin/python3.7

Viewed 9235

Having an issue with my python install and various packages after trying to get to grips with pipenv (clearly didnt go well).

➜ which Python
/usr/bin/Python

➜ which python3.8
/usr/local/bin/python3.8

Then any command I run that isn't directly a python command throws a bad interpreter error

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

➜ django-admin
zsh: /usr/local/bin/django-admin: bad interpreter: /usr/local/opt/python/bin/python3.7: no such file or directory

Not entirely sure what the cause is, so I am struggling to figure out how to resolve it. But basically any command that I run which involves a python package throws the same error

2 Answers

Install pip this way:

First download get-pip:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then install pip:

python3 get-pip.py

Check pip installation:

$pip -V
pip 20.2.2 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

One way to solve the pip issue is to link pip with a specific python version. Say for example you want to use pip to install GeoPandas. In this example, you can link a specific python version with pip by using the command:

python3.8 -m pip install geopandas

Of course this only works if you have python3.8 installed! This should overcome the bad interpreter message without having to change any zsh or bash_profile files.

Here is a link with further explanation:

https://snarky.ca/why-you-should-use-python-m-pip/

Related