$ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
$ sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib

I encountered this error while working on Django. I have it working on virtualenv with Django==1.3 but not on Django==1.5 where I have to issue the commands above.

In OS X El Capitan you can't do these links without disabling system protection but it works well if you link to /usr/local/lib


pip install psycopg2-binary

works like a charm!

Discussion on source+wheel distribution (pyscopg2) vs a separate binary distribution (psycopg2-binary): https://www.postgresql.org/message-id/CA%2Bmi_8bd6kJHLTGkuyHSnqcgDrJ1uHgQWvXCKQFD3tPQBUa2Bw%40mail.gmail.com

Explanation on the decision to release psycopg2-binary: http://initd.org/psycopg/articles/2018/02/08/psycopg-274-released/

However, there are reports of psycopg2-binary not satisfying psycopg2 dependencies. More discussion here: https://github.com/psycopg/psycopg2/issues/674


I found a solution that worked for me when dealing with a similar issue on rails. Add the following to your .bash_profile, .bash_rc, or equivalent:

export DYLD_FALLBACK_LIBRARY_PATH=/Applications/Postgres.app/Contents/MacOS/lib:$DYLD_LIBRARY_PATH

(Assuming you installed Postgres.app in the default location). Then restart your terminal session and try again.

Exporting to DYLD_LIBRARY_PATH directly can cause serious problems with other apps that depend on it, but using the fallback path avoids these problems.

See also: https://github.com/PostgresApp/PostgresApp/issues/109#issuecomment-18387546

EDIT: It seems that setting DYLD_FALLBACK_LIBRARY_PATH causes an error when you try to run psql. To fix this, you can add the following two lines to your .bash_profile:

alias psql="(. ~/.bash_profile; unset DYLD_FALLBACK_LIBRARY_PATH; psql)";

This is assuming that you're using bash and that your .bash_profile is located in your home directory. If that's not the case (or if you're using a .bashrc or other environment setup instead of .bash_profile) change the ~/.bash_profile part of the command to the path to your environment setup script.

The aliased command basically starts a subshell which does not effect your current bash environment. So when it unsets the DYLD_FALLBACK_LIBRARY_PATH variable, it's only temporary. After you exit psql the environment variable will be set again.


This happened to me after upgrading Postgresql, and after installing psycopg2 in my virtualenv. Reinstalling (re-building) worked for me.

pip uninstall psycopg2
pip install psycopg2

This problem cost me the whole morning to solve. I found the discussion on http://initd.org/psycopg/articles/2010/11/11/links-about-building-psycopg-mac-os-x/ really helpful. Thanks to Jurie's answer, the solution to my problem (in Mac) is as below:

  1. Install openssl 1.0.0 using brew:

     brew install openssl
    
  2. using the following command:

    export DYLD_LIBRARY_PATH=/usr/local/Cellar/openssl/**1.0.1x**/lib
    

    replace 1.0.1x part with your current version. For me it is 1.0.1h.

Hope this helps!

EDIT: After one day, I found that the second command has to be entered every time when needing to connect to database, so not a permanent solution to this problem.