Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 346
Fenwick17 Avatar asked Jul 25 '20 13:07

Fenwick17


People also ask

How do I download pip3 on Linux?

To install pip3 on Ubuntu or Debian Linux, open a new Terminal window and enter sudo apt-get install python3-pip . To install pip3 on Fedora Linux, enter sudo yum install python3-pip into a Terminal window. You will need to enter the administrator password for your computer in order to install this software.


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)
like image 83
arilwan Avatar answered Oct 13 '22 19:10

arilwan


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/

like image 1
Scott McMahan Avatar answered Oct 13 '22 18:10

Scott McMahan