Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 464
Aidan Ewen Avatar asked Oct 06 '15 19:10

Aidan Ewen


2 Answers

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.

like image 152
Nandeep Mali Avatar answered Sep 20 '22 05:09

Nandeep Mali


The reason is indeed psycopg2 using relative paths to a few PostgreSQL libraries. To fix it I used

sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.4/lib/libpq.5.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libcrypto.1.0.0.dylib /Library/PostgreSQL/9.4/lib/libcrypto.1.0.0.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libssl.1.0.0.dylib /Library/PostgreSQL/9.4/lib/libssl.1.0.0.dylib /Library/Python/2.7/site-packages/psycopg2/_psycopg.so

to convert the relative paths to absolute ones. Of course you'd need to do this every time you reinstall psycopg2.

like image 44
ArtHarg Avatar answered Sep 21 '22 05:09

ArtHarg