Search code examples
pythonmacospippsycopg2

Can't install psycopg2 package through pip install on MacOS


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

Why is this happening?


Solution

  • 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