0

Would like to install python packages (specifically psycopg2) using pip on CentOS. Cannot understand with what's wrong with my python3 installation, pipnot recognized:

$pip install psycopg2
-bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory

$pip install --upgrade pip
-bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory

$ python3.7 -V
Python 3.7.2

$which python3.7
/usr/local/bin/python3.7

Any idea why pip cannot work?

arilwan
  • 3,374
  • 5
  • 26
  • 62
  • Possible duplicate of [pip3: bad interpreter: No such file or directory](https://stackoverflow.com/questions/51373063/pip3-bad-interpreter-no-such-file-or-directory) – phd Apr 16 '19 at 16:27
  • https://stackoverflow.com/search?q=-bash%3A+%2Fusr%2Fbin%2Fpip%3A+%2Fusr%2Fbin%2Fpython%3A+bad+interpreter%3A+No+such+file+or+directory – phd Apr 16 '19 at 16:27

1 Answers1

2

You can invoke the pip module from your preferred Python interpreter by running: python3.7 -m pip install psycopg2

Josep Valls
  • 5,483
  • 2
  • 33
  • 67
  • To expand on _why_ this doesn't work, pip is looking for your Python interpreter in `/usr/bin`, however CentOS installs the interpreter to `/usr/local/bin` by default. – Larkeith Apr 16 '19 at 15:01
  • @Larkeith How do I change my default Python interpreter path to `/usr/local/bin` – arilwan Apr 16 '19 at 15:09
  • @arilwan There's a couple options - personally, I set up a soft link (`ln -s /usr/local/bin/python3.7 /usr/bin/python3.7`), however you should make sure pip is looking for the correct version of Python first with `head -n1 /usr/bin/pip` (or whatever your local pip installation's path is). I haven't tried this myself, but you could also modify the shebang in your pip installation (same line from before) to point towards your Python location; The main issue this might have is pip might revert it when you update. – Larkeith Apr 16 '19 at 15:28