Psycopg2 installation error, library not found for -lssl

I run "sudo pip install psycopg2" and I get a bunch of output that looks like

cc -DNDEBUG -g -fwrapv -Os ..... ..... cc -DNDEBUG -g -fwrapv -Os ..... ..... 

And at the end he says:

 ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1 ---------------------------------------- Cleaning up... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/bz/pvj1g9xj16d10pjjgbrfl3fw0000gn/T/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/bz/pvj1g9xj16d10pjjgbrfl3fw0000gn/T/pip-uE3thn-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/bz/pvj1g9xj16d10pjjgbrfl3fw0000gn/T/pip_build_root/psycopg2 Storing debug log for failure in /Users/Tyler/Library/Logs/pip.log 



By running easy_install or by doing this from the source , both give me the same error at the end (the part about the library that was not found for -lssl).




Running brew install (or upgrade) openssl gives below

 $ brew upgrade openssl Error: openssl-1.0.1h already installed 

Can anyone help me out?

+78
python postgresql psycopg2
Oct 9 '14 at 21:17
source share
11 answers

For anyone looking for a solution for this on macOS Sierra 10.12: I fixed this by installing command line tools:

 xcode-select --install 

After that, pip install psycopg2 should work.

If this is not the case, you can also try setting a link to brew openssl:

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

with openssl installed via brew. Please note that brew link openssl --force no longer works:

 $ brew link openssl --force 17.5s Warning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew openssl. Instead, pass the full include/library paths to your compiler eg: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib 

As @macho points out below, if this still doesn't work, you might have to use the --no-cache option for pip, for example.

 env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install psycopg2 
+204
Aug 31 '16 at 8:39
source share

When brew link openssl starts up, the following message appears:

 $ brew link openssl Warning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew openssl. Instead, pass the full include/library paths to your compiler eg: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib 

Following the advice here, run the pip command that you should use:

 $ pip install -r requirements.txt --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib" 
+19
Apr 09 '17 at 17:10
source share

I had OpenSSL installed from brew ( brew install openssl )

The following worked for me:

 export LDFLAGS="-L/usr/local/opt/openssl/lib" export CPPFLAGS="-I/usr/local/opt/openssl/include" pip install psycopg2 
+13
May 20 '19 at
source share

What worked for me was the hint given in the command for openssl communication,

 $ brew link openssl Warning: Refusing to link macOS-provided software: openssl If you need to have openssl first in your PATH run: echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc For compilers to find openssl you may need to set: export LDFLAGS="-L/usr/local/opt/openssl/lib" export CPPFLAGS="-I/usr/local/opt/openssl/include" $ export LDFLAGS="-L/usr/local/opt/openssl/lib" $ export CPPFLAGS="-I/usr/local/opt/openssl/include" $ pip install psycopg2 Collecting psycopg2 Using cached https://files.pythonhosted.org/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz Installing collected packages: psycopg2 Running setup.py install for psycopg2 ... done Successfully installed psycopg2-2.8.2 
+3
May 15 '19 at 9:59
source share

On the Mojave, I added them to .bash_profile

 export PATH="/usr/local/opt/openssl/bin:$PATH" export LDFLAGS="-L/usr/local/opt/curl/lib -L/usr/local/opt/openssl/lib" export CPPFLAGS="-I/usr/local/opt/curl/include -I/user/local/opt/openssl/include" 

then was able to install psycopg 2.8.3 in python 3.7.4 virtualenv.

This is after reinstalling xcode and command line tools.

All answers above helped!

+2
Aug 22 '19 at 22:39
source share

This issue recently occurred in High Sierra, having just installed Python 3.7 in virtualenv.

The solution is to use a later version of psycopg2. Version 2.7.7 worked, but 2.7.1 did not.

+1
03 Mar. '19 at 3:52
source share

Using Fish, the following two teams solved this problem for me after installing OpenSSL using Homebrew.

 set -gx LDFLAGS "-L/usr/local/opt/openssl/lib" set -gx CPPFLAGS "-I/usr/local/opt/openssl/include" 

Use brew info openssl for up-to-date information.

+1
Aug 27 '19 at 17:01
source share

Instead of installing psycopg2 , install psycopg2-binary from the same authors:

 pip install psycopg2-binary 

Here is what the documentation for this PyPI package says:

You can [...] get a standalone package that does not require a compiler or external libraries by installing the psycopg2-binary package from PyPI:

 $ pip install psycopg2-binary 

A binary package is a practical choice for development and testing, but in production it is recommended to use a package created from the source code.

0
Jun 14 '19 at 8:14
source share

I had this problem on the Mojave. Mojave does not create the / usr / include directory that psycopg2 needs to install. This was not obvious. I found a solution here: How to update Xcode from a command line that links to: https://forums.developer.apple.com/thread/104296

0
01 Sep '19 at 14:21
source share

This is a problem with the new version of macOs where pip cannot install cryptography . What fixed my problem was by providing env for the install command:

 brew install openssl env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" <YOUR COMMAND HERE> 

You can replace <YOUR COMMAND HERE> with pip install cryptography or pip install <SOMETHING THAT REQUIRES cryptography> , for example.

Link to article: Fix macOS Sierra fatal error: file "openssl / opensslv.h" or "openssl / aes.h" not found

0
Sep 19 '19 at 12:05
source share

I managed to fix this using:

 brew unlink openssl && brew link openssl --force 

I'm not sure how this differs from the uninstall / update brew that I did in OpenSSL in the previous attempts I made. My guess is that these operations left some of the “erroneous” shared libraries that prevented it from working. Please note that this also fixes problems installing python cryptography module.

-3
Jan 14 '15 at
source share



All Articles