Solved: linker command failed when installing psycopg2 with pip3

Recently another young developer had the following problem when he tried to execute

 pip3 install psycopg2

and he got this error.

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

----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-f4zsk3q_/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/tmp/pip-record-9kfvspoc/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-f4zsk3q_/psycopg2/

The problem is that a library is missing. As you can see on this line

 ld: library not found for -lssl

This is how we solved it

Step 1:
Double-check if openssl is installed and install it if not.

brew install openssl

Step 2:
Check if you use bash/zsh/fish or whatever and identify the config file. He is using zsh on mac so the file is

~/.zshrc
. So at the end of this file we added this line:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
. This add the path to the openssl library to the environment variable
LIBRARY_PATH
. Now you can reload the file with

source ~/.zshrc

Now you should be ready to install psycopg2 with pip3.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.