导入 psycopg2 库时出现错误:libssl.1.0.0.dylib 未加载。

60

当我尝试运行命令时:

import psycopg2

我遇到了这个错误:

ImportError: dlopen(/Users/gwulfs/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
  Referenced from: /Users/gwulfs/anaconda/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Reason: image not found
到目前为止,我已经尝试了brew install openssl并参考了以下链接(但没有成功):psycopg2安装错误-库未加载:libssl.dylibPostgresapp和psycopg2在OS X上的安装Psycopg2未找到图像

4
如果您使用的是bash(OS X上的默认shell),请将以下行添加到〜/ .bash_profile中:export DYLD_FALLBACK_LIBRARY_PATH=$HOME/anaconda/lib:$DYLD_FALLBACK_LIBRARY_PATH。或者,如果您使用的是fish shell,请将以下内容添加到您的config.fish中(通常位于〜/ .config / fish / config.fish):set -x DYLD_FALLBACK_LIBRARY_PATH $HOME/anaconda/lib $DYLD_FALLBACK_LIBRARY_PATH - Answeror
2
同样的问题在这篇文章中得到了解决:https://dev59.com/N2Ag5IYBdhLWcg3wI4AR#23945292 - Xing Shi
@xing-shi是正确的!请不要搞混符号链接(在其他帖子中提到过这个问题),甚至环境变量($DYLD_FALLBACK_PATH)。请查看下面我的解决方案:https://dev59.com/-14d5IYBdhLWcg3wCOuD#36872624 - alichaudry
22个回答

0

在运行brew upgrade后,我遇到了这个问题,它将openssl从1.0.0更新到了1.1.1。这导致了问题中的错误,因为我正在使用pyscopg 2.7.4,它被固定在openssl@1.0上。更近期的psycopg版本(>2.8)被固定在openssl@1.1上。

因此,在这种情况下,您有两个选择:要么将psycopg升级到2.8.1或更高版本(在您的Pipfile/Pipfile.lock等文件中),要么使用以下命令强制brew继续使用openssl@1.0,该命令来自https://github.com/Homebrew/homebrew-core/issues/47348#issuecomment-560001981

brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/64555220bfbf4a25598523c2e4d3a232560eaad7/Formula/openssl.rb -f

0

Homebrew将默认的openssl从v1.0升级到v1.1。如果您尝试过@Scott的升级openssl解决方案:

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

你可能会遇到ssh问题。你需要升级openssh版本。

brew upgrade openssh

根据这篇博客:https://blog.junjizhi.com/all/2019/12/17/git-fetch-libssl-error.html

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接