Python 未加载导入 psycopg2 库:libssl.1.0.0.dylib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27264574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:35:22  来源:igfitidea点击:

Import psycopg2 Library not loaded: libssl.1.0.0.dylib

pythondatabasepostgresqlpython-2.7postgresql-9.3

提问by Gideon

When I try to run the command:

当我尝试运行命令时:

import psycopg2

I get the error:

我收到错误:

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

So far I have tried brew install openssland have referenced (with no luck):

到目前为止,我已经尝试brew install openssl并参考了(没有运气):

psycopg2 installation error - Library not loaded: libssl.dylib

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

http://joshuakehn.com/2013/10/13/Postgresapp-and-psycopg2-on-OS-X.html

http://joshuakehn.com/2013/10/13/Postgresapp-and-psycopg2-on-OS-X.html

Psycopg2 image not found

找不到 Psycopg2 图像

回答by Scott Brenstuhl

EDIT: potentially dangerous, read comments first!

编辑:潜在危险,请先阅读评论!

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

请参阅下面更安全的答案: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.

在你发布它大约一个小时后,我遇到了这个确切的问题,然后才弄清楚。我使用的是 Mac OS X Yosemite、Python 2.7 和 Postgresql 应用程序。

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

然后将它们重新链接(用您的 Mac 用户名替换 YOURUSERNAME。我发现使用 tab 来完成每个步骤,以确认目录很有帮助):

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

我相信其他解决方案对您不起作用,因为您的版本在 anaconda 中。

回答by X.L.

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

不要在系统库目录中使用符号链接,而是将 设置$DYLD_FALLBACK_LIBRARY_PATH为包含 anaconda 库。例如:

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

回答by tyton

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

我不得不稍微改变 Scott Brennstuhl 的回答: 1. 删除损坏的符号链接:

$ 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:
  1. 与 postgres 包含的驱动程序重新链接:
$ 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

回答by yottabytt

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

如果您在 /usr/local/Cellar 目录中有 openssl,请执行以下操作来解决未加载的库:libssl.1.0.0.dylib 错误

  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

  1. 须藤cp /usr/local/Cellar/openssl/<<版本>>/lib/libssl.1.0.0.dylib /usr/lib

  2. 执行完步骤1后,如果仍然出现Library not loaded:libcrypto.1.0.0.dylib 错误。执行以下
        sudo cp /usr/local/Cellar/openssl/<< version>>/lib/libcrypto.1.0.0.dylib /usr/lib

回答by Shoeb Ahmed Mogal

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)

我尝试了 pip install psycopg2,它给出了类似的问题。然后我尝试了 conda install psycopg2,它奏效了!还要确保您使用的 pip 属于 anaconda(哪个 pip)

回答by Jim Bob

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

关于上面 XL 的回答,当我已经在使用 pip 时我不想使用 Anaconda,所以我只是给它提供了对我有用的 Postgres 库的路径(我在 Mac OS 10.10 上使用 PostgreSQL.app )...

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

回答by Hymanyen_2000

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

conda install psycopg 对我有用。它更新了以下软件包 以下软件包将被更新:

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

回答by alichaudry

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:

选项 1。这解决了我们的问题,而不会弄乱环境变量。在你的 shell 中运行这个:

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

Boom! This upgrades the symbolic links in /usr/localfor libssland libcrypto. Now import psycopg2works like a charm.

繁荣!这会升级/usr/localforlibssl和 中的符号链接libcrypto。现在import psycopg2就像一个魅力。

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

选项 2.如果出于某种原因您想维护 中的当前符号链接usr/local,请在您的 shell 中运行此命令:

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

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

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

只需确保$HOME/anaconda/lib用实际的 lib 路径替换上面的内容。就我而言,这是$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 exportstatement to your ~/.bash_profileor ~/.bashrcfile.

这仅适用于您当前所在的 shell/bash 会话。要使更改持久化,请将export语句添加到您的~/.bash_profile~/.bashrc文件中。

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

想法:IMO #1 是处理这个问题的正确方法,但我留下了 #2 以防有些人更喜欢使用环境变量而不是修复符号链接(例如,如果他们的软件依赖于较旧的 openssl文件版本)。

回答by cwnewhouse

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

我的设置风格与 OP 略有不同:我Postgres.app在 Mac 上使用,并且在virtualenv; 但症状相似。

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

对我来说,这是Postgres.app在我的本地从 9.3更新到 9.5之后发生的,错误清楚地显示psycopg2路径libssl.1.0.0.dylib指向旧的 9.3 数据目录位置(image此错误中引用的位置?)。向我添加奇怪的东西ENV或删除符号链接我不确定这对我来说肯定不合适。我通过卸载然后psycopg2以与它工作时相同的方式重新安装来解决它- 一点也不觉得很危险的东西:

 # In my virtualenv
 pip uninstall psycopg2
 pip install psycopg2

Then I was all good!

那我一切都好!

回答by NSTJ

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

在 Homebrew 不允许我强制链接后openssl,以下工作正常:

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 virtualenvon macOS)

(此安装virtualenv在 macOS 上成功)