Import psycopg2 Library not loaded: libssl.1.0.0.dylib

帅比萌擦擦* 提交于 2019-11-27 00:03:14

Instead of playing with symlinks in system library dirs, set the $DYLD_FALLBACK_LIBRARY_PATH to include the anaconda libraries. eg:

export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib/:$DYLD_FALLBACK_LIBRARY_PATH
Scott Brenstuhl

EDIT: potentially dangerous, read comments first!

See a much safer answer below: https://stackoverflow.com/a/30726895/308315


I ran into this exact issue about an hour after you posted it and just figured it out. I am using Mac OS X Yosemite, Python 2.7, and the Postgresql app.

There seems to be a non-working symlink set by default (or I introduced it while troubleshooting), to fix it first remove the incorrect links:

$ sudo rm /usr/lib/libssl.1.0.0.dylib
$ sudo rm /usr/lib/libcrypto.1.0.0.dylib

Then re-link them with (replace YOURUSERNAME with your Mac user name. I found it helpful to use tab to complete each step, to confirm the directory):

$ sudo ln -s /Users/YOURUSERNAME/anaconda/lib/libssl.1.0.0.dylib /usr/lib
$ sudo ln -s /Users/YOURUSERNAME/anaconda/lib/libcrypto.1.0.0.dylib /usr/lib

I believe the other solutions didn't work for you because your version is in anaconda.

After bashing my head against the wall for a couple hours, these two solutions are guaranteed to work:

Option 1. This solves our problem without messing around with environment variables. Run this in your shell:

brew install --upgrade openssl
brew unlink openssl && brew link openssl --force

Boom! This upgrades the symbolic links in /usr/local for libssl and libcrypto. Now import psycopg2 works like a charm.

Option 2. If for some reason you would like to maintain the current symbolic links in usr/local, run this command in your shell:

export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib/:$DYLD_FALLBACK_LIBRARY_PATH

Just make sure to replace $HOME/anaconda/lib above with the actual lib path. In my case, this was $HOME/miniconda2/envs/ali/lib.

This will only work for the shell/bash session you're currently in. To make the change persistent, add the export statement to your ~/.bash_profile or ~/.bashrc file.

Thoughts: IMO #1 is the proper way to deal with this problem, but I left #2 in case some people prefer working with environment variables rather than fixing symbolic links (if, for example, they have software with a dependency on the older openssl file versions).

conda install psycopg works for me. It updates the following packages The following packages will be UPDATED:

conda:      3.19.1-py27_0 --> 4.0.5-py27_0
openssl:    1.0.2f-0      --> 1.0.2g-0
pip:        8.0.2-py27_0  --> 8.1.0-py27_0
setuptools: 19.6.2-py27_0 --> 20.2.2-py27_0
wheel:      0.26.0-py27_1 --> 0.29.0-py27_0

After Homebrew wouldn't allow me to force link openssl the following worked fine:

pip install --global-option=build_ext \
            --global-option="-I/usr/local/opt/openssl/include" \
            --global-option="-L/usr/local/opt/openssl/lib" psycopg2

(this installation succeeded in a virtualenv on macOS)

In relation to X.L.'s answer above, I didn't want to use Anaconda when I'm already using pip, so I just gave it the path to the Postgres libraries which worked for me (I'm using PostgreSQL.app on Mac OS 10.10)...

export DYLD_FALLBACK_LIBRARY_PATH=/Library/PostgreSQL/9.5/lib:$DYLD_FALLBACK_LIBRARY_PATH
tyton

I had to vary Scott Brennstuhl's answer a little: 1. Remove broken symlinks:

$ sudo rm /usr/lib/libssl.1.0.0.dylib
$ sudo rm /usr/lib/libcrypto.1.0.0.dylib
$ sudo rm /usr/lib/libpq.5.dylib
  1. Relink with postgres' included drivers:
$ sudo ln -s   /Applications/Postgres.app/Contents/Versions/9.4/lib/libssl.1.0.0.dylib /usr/lib    
$ sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libcrypto.1.0.0.dylib /usr/lib
$ sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib  /usr/lib

My flavor of setup was a little different than the OP: I'm using Postgres.app on Mac and am within a virtualenv; but the symptoms were similar.

For me, this occurred right after updating my Postgres.app from 9.3 to 9.5 on my local, and the error clearly showed the psycopg2 path for libssl.1.0.0.dylib was pointing to the old 9.3 data directory location (the image referenced in this error?). Adding weird things to my ENV or removing symlinks I'm not sure the impact of definitely didn't feel right to me. I solved it by uninstalling then re-installing psycopg2 the same way I had when it was working - something that doesn't feel very dangerous at all:

 # In my virtualenv
 pip uninstall psycopg2
 pip install psycopg2

Then I was all good!

Do the following to resolve Library not loaded:libssl.1.0.0.dylib error if you have openssl in /usr/local/Cellar directory

  1. sudo cp /usr/local/Cellar/openssl/<<version>>/lib/libssl.1.0.0.dylib /usr/lib

  2. After doing step 1, if you still get Library not loaded:libcrypto.1.0.0.dylib error. Do the following
        sudo cp /usr/local/Cellar/openssl/<<version>>/lib/libcrypto.1.0.0.dylib /usr/lib

I tried pip install psycopg2 which was giving similar issues. Then I tried conda install psycopg2, which worked! Also make sure the pip you are using belongs to anaconda (which pip)

I was having this issue on Mac, trying ln -s was giving me ln: /usr/lib/libssl.1.0.0.dylib: Operation not permitted I didn't want to mess with my system. Instead What worked for me is to simply install psycopg2-binary : pip install psycopg2-binary

This installed psycopg2-binary-2.8.3 version

After trying for more than a day I came to the below solution.

  • brew reinstall openssl@1.0
  • disable csrutil -> google it how to disable it, so that we could copy something
    to /usr/lib
  • copy libssl.1.0.0.dylib to /usr/lib I did- sudo cp /usr/local/Cellar/openssl/1.0.2s/lib/libssl.1.0.0.dylib /usr/lib
  • copy libcrypto.1.0.0.dylib to /usr/lib I did- sudo cp /usr/local/Cellar/openssl/1.0.2s/lib/libcrypto.1.0.0.dylib /usr/lib

Similarly, if you face issue for Library not loaded: libssl.1.0.0.dylib just change the version from 1.0 to 1.1 of openssl and copy libssl.1.1 instead libssl.1.0 and libcrypto.1.1 instead libcrypto.1.0.0

Done you are all set to enjoy psycopg2 in mac.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!