Can't install psycopg2 package through pip install on MacOS

67,025

Solution 1

I fixed this by installing Command Line Tools

xcode-select --install

then installing openssl via Homebrew and manually linking my homebrew-installed openssl to pip:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2

on macOS Sierra 10.12.1

Solution 2

Try installing it with:

pip install psycopg2-binary

Solution 3

brew install postgresql

If postgresql exist then run:

brew upgrade postgresql
sudo pip install psycopg2

In venv:

env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib' pip install psycopg2==2.8.4

If you need use only the command pip install psycopg2 export the path in macOSX:

export LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib"

Solution 4

I fixed it with:

brew reinstall openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

Solution 5

Running into a similar problem using pipenv install psycopg2:

ld: library not found for -lssl', ' clang: error: linker command failed with exit code 1 (use -v to see invocation)', " error: command 'clang' failed with exit status 1", '
----------------------------------------',

I tried all of the recommendations above and none of them worked. I'd faced this problem in another virtualenv a few months ago and remembered reading something about this being a psycopg2 version issue. So I tried installing with 2.7.1 and 2.8.3 and both still failed. Somehow version 2.7.7 worked:

pipenv install psycopg2==2.7.7

Wish I had time to look into this further to understand what's really happening. But for now I don't and this worked.

Share:
67,025
Jome
Author by

Jome

Updated on July 08, 2022

Comments

  • Jome
    Jome almost 2 years

    I am working on a project for one of my lectures and I need to download the package psycopg2 in order to work with the postgresql database in use. Unfortunately, when I try to pip install psycopg2 the following error pops up:

    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/clang' failed with exit status 1
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/clang' failed with exit status 1
    

    Does anyone know why this is happening? Thanks in advance!