Import psycopg2 Library not loaded: libssl.1.0.0.dylib

前端 未结 20 2423
囚心锁ツ
囚心锁ツ 2020-11-28 21:02

When I try to run the command:

import psycopg2

I get the error:

ImportError: dlopen(/Users/gwulfs/anaconda/lib/python2.7/si         


        
相关标签:
20条回答
  • 2020-11-28 21:42

    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.

    0 讨论(0)
  • 2020-11-28 21:43

    I had the same problem when I updated openssl from 1.0.0 to 1.1.1d, and this fixed my problem:

    brew upgrade postgresql
    
    0 讨论(0)
  • 2020-11-28 21:45

    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).

    0 讨论(0)
  • 2020-11-28 21:45

    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
    
    0 讨论(0)
  • 2020-11-28 21:48

    Homebrew upgrades default openssl from v1.0 to v1.1. If you tried @Scott solution to upgrade openssl:

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

    you may run into ssh problem. You need to upgrade openssh as well.

    brew upgrade openssh
    

    according to this blog: https://blog.junjizhi.com/all/2019/12/17/git-fetch-libssl-error.html

    0 讨论(0)
  • 2020-11-28 21:50

    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)

    0 讨论(0)
提交回复
热议问题