I did a simple pip install psycopg2
on mac system. It installed fine, but when I try to use psycopg2 I get the error:
Reason: Incompatible libra
I ran into a similar problem after upgrading to Mountain Lion.
Instead of copying libssl.* files per Slack's suggestion, make sure that /usr/lib/libssl.dylib
is actually a soft link to the most up-to-date version of the library.
E.g., on my machine, ls -l /usr/lib/libssl*
gives:
lrwxr-xr-x 1 root wheel 46B Jun 27 15:24 /usr/lib/libssl.1.0.0.dylib -> /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
lrwxr-xr-x 1 root wheel 27B Jul 30 10:31 /usr/lib/libssl.dylib -> /usr/lib/libssl.1.0.0.dylib
If libssl.dylib
doesn't link to the version that the error version mentions, make sure you have that version of the library, and then make sure /usr/lib/libssl.dylib
points to it, and not an older version.
If the link doesn't exist, create it like so
sudo ln -s library_to_link_to link_to_create
using, of course, the proper locations for your machine. For me, this turned out to be:
sudo ln -s /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
Edit:
It seems like some are having trouble with part of my solution. Namely, deleting these important libraries even temporarily causes problems with the operating system.
Per Purrell's answer, make sure you include the -fs
flags when you use the ln
command, which helps ensure that the libraries don't go missing for a short period of time. E.g.,
sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
I had similar problem on my Mac OS High Sierra.
ImportError: dlopen(/Users/chicha/Projects/CTMR/sample_registration/romans_env/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: /opt/local/lib/libssl.1.0.0.dylib
But after "pip install postgres" it's work fine. According to pip show - "postgres is a high-value abstraction over psycopg2". While installing it's also installed psycopg2-binary and psycopg2-pool. So, all together they have repaired the situation somehow.
On OSX 10.11, El Capitan, solution with replacing symlinks reported Operation not permitted
. Solution that worked for me was using brew and setting up DYLD_LIBRARY_PATH. So:
brew install openssl
Find where openssl brew libs are located (brew --prefix openssl
can help), start searching from directory /usr/local/Cellar/openssl
. In my case it is in /usr/local/Cellar/openssl/1.0.2d_1/lib
Finally set up DYLD_LIBRARY_PATH, i.e. add a line like this into .bash_profile :
# replace location of lib files with folder name you found in previous step
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/Cellar/openssl/1.0.2d_1/lib
UPDATE: More generic/better alternatives are (thanks to @dfrankow):
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(brew --prefix openssl)/lib
DYLD_FALLBACK_LIBRARY_PATH
instead - check thisRestart shell, or just source ~/.bash_profile
, reinstall psycopg2:
pip uninstall psycopg2
pip install psycopg2
and test if it works:
$ python -c"import psycopg2 ; print('psycopg2 is now ok')"
Worked for me:
env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib
-L/usr/local/opt/readline/lib' pip install psycopg2
Source: https://code-examples.net/en/q/93ae48