Search code examples
pythonpsycopg2osx-elcapitanlibssl

How do I run psycopg2 on El Capitan without hitting a libssl error


I've got a python django dev setup on my mac and have just upgraded to El Capitan.

I've got psycopg2 installed in a virtualenv but when I run my server I get the following error -

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/aidan/Environments/supernova/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/aidan/Environments/supernova/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Reason: image not found

I've tried reinstalling my virtualenv

pip install -f requirements.txt

And I've tried upgrading psycopg2

pip uninstall psycopg2
pip install psycopg2

But I'm still getting the same error.

I've also tried adding symlinks to /usr/lib but El Capitan's new rootless thing doesn't allow it -

$ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib
 /usr/lib
ln: /usr/lib/libssl.1.0.0.dylib: Operation not permitted

So I tried /usr/local to no avail.

The system version of openssl seems to be 1.0.2 -

$ openssl version
OpenSSL 1.0.2d 9 Jul 2015

How do I fix this?


Solution

  • I tried the following:

    I have brew installed on my machine. Running $ brew doctor gave me a suggestion to do the following:

    $ sudo chown -R $(whoami):admin /usr/local

    Once this was done, I re-installed psycopg2 and performed the following:

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

    Please note the version of your PostgreSQL and the path /usr/local/lib.

    Doing this got me back to a working setup again.

    P.S.: The brew suggested step might not be relevant here but I put this up because you were seeing permission issues. You could also disable rootless mode.