Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psycopg2 installation error - Library not loaded: libssl.dylib

I try to install psycopg2 in a virtualenv using pip, the compilation looks ok, it says "Successfully installed psycopg2", but when I try to import it in python interpreter (in virtualenv), it indicates error:

  File "<stdin>", line 1, in <module>
  File "/Users/me/sites/env/trackmap/lib/python2.7/site-packages/psycopg2/__init__.py", line 67, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/me/sites/env/trackmap/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.dylib
  Referenced from: /Users/me/sites/env/trackmap/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Reason: Incompatible library version: _psycopg.so requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8

The thing is I install it successfully using pip in my other virtual env before, like, several weeks ago, and get it working with the postgresql on my mac. I am wondering if this is a problem of compiler? I saw some warnings like shortens from 64-bit to 32-bit during the installation of psycopg2. My compiler is i686-apple-darwin11-llvm-gcc-4.2, default one on mac os x lion.

I see several posts related to psycopg2 install but most of them are solved by installing in a virtual env. So...could anyone give me a suggestion? Thank you! Really appreciated.

p.s. If you need the compilation log of installing psycopg2 please let me know, I didn't paste it here because it is too long.

like image 497
Yulong Avatar asked Jul 06 '12 15:07

Yulong


3 Answers

Does the error say libssl.dylib version is too old?

On my mac, the error is that libssl.dylib and libcrypto.dylib is too old for pyscopg to use. The openssl package used by mac is 0.98, while pyscopg needs 1.0.0 or later version.

My solution is this:

  1. install openssl from brew

    $ brew install openssl
    
  2. copy libssl.1.0.0.dylib and libcrypto.1.0.0.dylib from /usr/local/Cellar/openssl/1.0.1c to /usr/lib/

    $ cd /usr/local/Cellar/openssl/1.0.1c/lib
    $ sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/lib/
    
  3. in /usr/lib directory, make a softlink libssl.dylib and libcrypto.dylib. You may have to remove the existing links.

    $ sudo rm libssl.dylib libcrypto.dylib
    $ sudo ln -s libssl.1.0.0.dylib libssl.dylib
    $ sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib
    
like image 82
ming.kernel Avatar answered Oct 17 '22 03:10

ming.kernel


I think in Mac we need:

export LDFLAGS="-L/usr/local/opt/openssl/lib"
like image 43
jiamo Avatar answered Oct 17 '22 04:10

jiamo


I had a similar issue. I had used Anaconda to install python and a number of packages and then later used pip to install psycopg2. I was able to fix the error by uninstalling psycopg2 and reinstalled it with the conda package manager instead of pip.

pip uninstall psycopg2
conda install psycopg2
like image 25
ansonw Avatar answered Oct 17 '22 05:10

ansonw