psycopg2安装错误 - 未加载库:libssl.dylib

Yul*_*ong 31 python psycopg2 virtualenv

我尝试psycopg2使用virtualenv 安装pip,编译看起来没问题,它说"成功安装了psycopg2",但是当我尝试在python解释器中导入它时(在virtualenv中),它表示错误:

  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
Run Code Online (Sandbox Code Playgroud)

问题是我pip在几周之前使用我的其他虚拟环境成功安装它,就像几个星期前一样,让它postgresql在我的Mac上工作.我想知道这是否是编译器的问题?我shortens from 64-bit to 32-bit在安装psycopg2时看到了一些警告.我的编译器是i686-apple-darwin11-llvm-gcc-4.2mac os x lion上的默认编译器.

我看到几个与psycopg2安装相关的帖子,但大多数都是通过安装在虚拟环境中解决的.那么......有人能给我一个建议吗?谢谢!非常感谢.

ps如果你需要安装psycopg2的编译日志,请告诉我,我没有在这里粘贴,因为它太长了.

min*_*nel 91

错误是否说libssl.dylib版本太旧了?

在我的Mac上,错误是这个,libssl.dylib并且libcrypto.dylib太旧了,pyscopg无法使用.opensslmac使用的包是0.98,而pyscopg需要1.0.0或更高版本.

我的解决方案是:

  1. 从brew安装openssl

    $ brew install openssl
    
    Run Code Online (Sandbox Code Playgroud)
  2. 复制libssl.1.0.0.dyliblibcrypto.1.0.0.dylib/usr/local/Cellar/openssl/1.0.1c/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/
    
    Run Code Online (Sandbox Code Playgroud)
  3. /usr/lib目录中,制作一个软链接libssl.dyliblibcrypto.dylib.您可能必须删除现有链接.

    $ 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
    
    Run Code Online (Sandbox Code Playgroud)

  • 在最新版本的 MacOS 中,`/usr/lib` 受 SIP 保护。按照这些说明使用 `/usr/local/lib` 对我有用。 (4认同)
  • 仅供参考http://stackoverflow.com/questions/11538249/python-pip-install-psycopg2-install-error - "Per Purrell的答案,请确保在使用ln命令时包含-fs标志,这有助于确保图书馆不会在短时间内失踪." (2认同)

jia*_*amo 34

我认为在 Mac 中我们需要:

export LDFLAGS="-L/usr/local/opt/openssl/lib"
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用的是配备 m1 芯片的 Mac。```export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"``` (2认同)

ans*_*onw 22

我有类似的问题.我曾使用Anaconda安装python和一些软件包,然后使用pip来安装psycopg2.我能够通过卸载psycopg2并使用conda包管理器而不是pip重新安装它来修复错误.

pip uninstall psycopg2
conda install psycopg2
Run Code Online (Sandbox Code Playgroud)

  • 对于我们在El Captian上使用Anaconda的人来说,这是一件容易的事(谢谢[新SIP](https://coolestguidesontheplanet.com/what-is-sip-in-osx-10-11-el-capitan/))。我简直不敢浪费自己的时间。 (2认同)

Rob*_*ujo 20

在OSX 10.11+(El Capitan或更高版本)解决方案上更换符号链接(参见上述 - /sf/answers/833830931/)sudo rm libssl.dylib libcrypto.dylib报告Operation not permitted.对我有用的解决方案是:

brew install openssl
Run Code Online (Sandbox Code Playgroud)

找到openssl brew lib所在的位置,从目录开始搜索/usr/local/Cellar/openssl.在我的情况下它是在/usr/local/Cellar/openssl/1.0.2d_1/lib

最后设置DYLD_LIBRARY_PATH,即将这样的行添加到.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
Run Code Online (Sandbox Code Playgroud)

重启shell,或者只source ~/.bash_profile测试它是否有效:

$ python -c"import psycopg2  ;   print('psycopg2 is now ok')"
Run Code Online (Sandbox Code Playgroud)

  • 或者一般来说:`export DYLD_LIBRARY_PATH = $ DYLD_LIBRARY_PATH:$(brew --prefix openssl)/ lib` (4认同)

goz*_*lli 13

谢谢@khrf的回答.

如果您使用的是postgres系统安装程序(而不是Postgres.app),请使用:

export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib
Run Code Online (Sandbox Code Playgroud)

~/.bash_profile如果你想避免每次都输入它,可以放在你的.