python pip install psycopg2 install error

后端 未结 10 1708
余生分开走
余生分开走 2020-11-27 15:31

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         


        
10条回答
  •  迷失自我
    2020-11-27 16:12

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

    • to use brew to find openssl location (a note, brew can be slow): DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(brew --prefix openssl)/lib
    • for development purposes maybe it is better to use DYLD_FALLBACK_LIBRARY_PATH instead - check this

    Restart 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')"
    

提交回复
热议问题