Installing psycopg2 on a Mac

Sometimes I really miss apt-get. Wish for the old days of linux and command prompt, lol. Pretty crazy installation for a Mac. Here’s what I had to do:

1. Get the latest source package from psycopg site. In my case, I got v2.6. Save this to your tmp dir

2. Follow installation using source package on this site. But things don’t really work first time, do they?

$ python setup.py build
$ sudo python setup.py install

After installing from source, I got the following error:

    import psycopg2
  File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in 
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
  Reason: image not found

3. Create new links under /usr/lib to resolve the above error:

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

On ElCapitan, you may get the following error:

ln: /usr/lib/liblibssl.1.0.0.dylib: Operation not permitted

This is a result of System Integrity Protection. You should instead create links under /usr/local/lib. That’s where you should be adding all your custom links which overrides the system and that ways the system setup is not altered.
But this still doesn’t resolve the errors. Still get the following error:

    import psycopg2
  File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in 
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
  Reason: image not found

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

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

2 thoughts on “Installing psycopg2 on a Mac

  1. Hi Daniel,
    Maybe you should try to copy the original libssl.1.0.0.dylib and libcrypto.1.0.0.dylib to /usr/lib/, delete/rename the existing symbolic links libssl.dylib and libcrypto.dylib and create them again with this commands:

    sudo ln -s libssl.1.0.0.dylib libssl.dylib
    sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib

    Hope this could resolve your problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s