python pip install psycopg2 install error

The accepted answer here is correct (except I think it must be ln -fs , in fact I think it might even risk destabalizing your OS if not (?)). After bumping into this and dealing with it I just want to collect the full solution for this issue and the other lib problem (libcrypto.1.0.0.dylib) you will run into for Postgres 9.* on Mountain Lion and Snow Leopard, and perhaps other systems. This also blocked me from running psql, which complained about the same two libs.

Essentially there are two later-version libs needed in /usr/lib, libssl and libcrypto. You can find the needed versions of these libs in the Postgres lib directory.

  • If you're OSX and installed the Enterprise DB version of Postgres this will be in /Library/PostgreSQL/9.2/lib.
  • For other install types of Postgres, look for the lib directory inside the Postgress install directory, e.g., for Postgress.app, find the lib directory in /Applications/Postgres.app/Contents/MacOS/lib,
  • for brew somewhere in /usr/local/Cellar,
  • on *nix, wherever your install is. But see first on *nix if your distro has later versions just through the package manager.

First copy the latest of these two libs from the Postgres lib directory to /usr/lib:

sudo cp /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
sudo cp /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib

Then update (or create) the /usr/lib symlinks for this libs. Either way the command is ln -fs:

sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib

Should be fixed. Pretty sure ln -fs is better than deleting the symlink and remaking it, so there is less chance of libssl being unfindable by something that needs it for the time it is not present (it does the same thing; it first deletes the symlink if it's already there, just faster than you can type it). Always wary of messing around on /usr/lib.


I ran into a similar problem after upgrading to Mountain Lion.

Instead of copying libssl.* files per Slack's suggestion, make sure that /usr/lib/libssl.dylib is actually a soft link to the most up-to-date version of the library.

E.g., on my machine, ls -l /usr/lib/libssl* gives:

lrwxr-xr-x  1 root  wheel    46B Jun 27 15:24 /usr/lib/libssl.1.0.0.dylib -> /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
lrwxr-xr-x  1 root  wheel    27B Jul 30 10:31 /usr/lib/libssl.dylib -> /usr/lib/libssl.1.0.0.dylib

If libssl.dylib doesn't link to the version that the error version mentions, make sure you have that version of the library, and then make sure /usr/lib/libssl.dylib points to it, and not an older version.

If the link doesn't exist, create it like so

sudo ln -s library_to_link_to link_to_create

using, of course, the proper locations for your machine. For me, this turned out to be:

sudo ln -s /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib

Edit:

It seems like some are having trouble with part of my solution. Namely, deleting these important libraries even temporarily causes problems with the operating system.

Per Purrell's answer, make sure you include the -fs flags when you use the ln command, which helps ensure that the libraries don't go missing for a short period of time. E.g.,

sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib

Worked for me:

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

Source: Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7