Problems using psycopg2 on Mac OS (Yosemite)

You need to replace the /usr/lib/libpq.5.dylib library because its version is too old.
Here's my solution to this problem:

$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old  
$ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib

If you are using PostgresApp, you need to run the following two commands:

sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old
sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib