postgresql python pip install psycopg2 安装错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11538249/
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
python pip install psycopg2 install error
提问by jerrymouse
I did a simple pip install psycopg2
on mac system. It installed fine, but when I try to use psycopg2 I get the error:
我pip install psycopg2
在mac系统上做了一个简单的。它安装得很好,但是当我尝试使用 psycopg2 时出现错误:
Reason: Incompatible library version: _psycopg.so requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8
pip freeze
shows psycopg2==2.4.5
just right. I have installed psycopg2 on several virtualenvs but this is the first time I am seeing such error. I tried uninstalling and reinstalling, same results. Please help
pip freeze
显示psycopg2==2.4.5
恰到好处。我已经在几个 virtualenv 上安装了 psycopg2,但这是我第一次看到这样的错误。我尝试卸载并重新安装,结果相同。请帮忙
采纳答案by Tim Camber
I ran into a similar problem after upgrading to Mountain Lion.
升级到 Mountain Lion 后,我遇到了类似的问题。
Instead of copying libssl.* files per Slack's suggestion, make sure that /usr/lib/libssl.dylib
is actually a soft link to the most up-to-date version of the library.
不要根据 Slack 的建议复制 libssl.* 文件,而是确保它/usr/lib/libssl.dylib
实际上是指向该库最新版本的软链接。
E.g., on my machine, ls -l /usr/lib/libssl*
gives:
例如,在我的机器上,ls -l /usr/lib/libssl*
给出:
lrwxr-xr-x 1 root wheel 46B Jun 27 15:24 /usr/lib/libssl.1.0.0.dylib -> /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
lrwxr-xr-x 1 root wheel 27B Jul 30 10:31 /usr/lib/libssl.dylib -> /usr/lib/libssl.1.0.0.dylib
If libssl.dylib
doesn't link to the version that the error version mentions, make sure you have that version of the library, and then make sure /usr/lib/libssl.dylib
points to it, and not an older version.
如果libssl.dylib
没有链接到错误版本提到的版本,请确保您拥有该版本的库,然后确保/usr/lib/libssl.dylib
指向它,而不是旧版本。
If the link doesn't exist, create it like so
如果链接不存在,请像这样创建它
sudo ln -s library_to_link_to link_to_create
using, of course, the proper locations for your machine. For me, this turned out to be:
当然,使用适合您机器的正确位置。对我来说,结果是:
sudo ln -s /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
Edit:
编辑:
It seems like some are having trouble with part of my solution. Namely, deleting these important libraries even temporarily causes problems with the operating system.
似乎有些人对我的部分解决方案有问题。也就是说,删除这些重要的库即使是暂时的也会导致操作系统出现问题。
Per Purrell's answer, make sure you include the -fs
flags when you use the ln
command, which helps ensure that the libraries don't go missing for a short period of time. E.g.,
根据Purrell 的回答,确保-fs
在使用ln
命令时包含标志,这有助于确保库不会在短时间内丢失。例如,
sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
回答by Purrell
The accepted answer here is correct (except I think it must be ln -fs , in fact I think it might even risk destabalizing your OS if not (?)). After bumping into this and dealing with it I just want to collect the full solution for this issue and the other lib problem (libcrypto.1.0.0.dylib) you will run into for Postgres 9.* on Mountain Lion and Snow Leopard, and perhaps other systems. This also blocked me from running psql, which complained about the same two libs.
这里接受的答案是正确的(除了我认为它必须是 ln -fs ,事实上我认为如果不是(?),它甚至可能会破坏你的操作系统)。在遇到这个问题并处理它之后,我只想收集这个问题的完整解决方案和另一个 lib 问题(libcrypto.1.0.0.dylib),你将在 Mountain Lion 和 Snow Leopard 上遇到 Postgres 9.*,以及也许其他系统。这也阻止了我运行 psql,它抱怨相同的两个库。
Essentially there are two later-version libs needed in /usr/lib
, libssl and libcrypto. You can find the needed versions of these libs in the Postgres lib directory.
本质上/usr/lib
,libssl 和 libcrypto 中需要两个更高版本的库。您可以在 Postgres lib 目录中找到这些库的所需版本。
- If you're OSX and installed the Enterprise DB version of Postgres this will be in
/Library/PostgreSQL/9.2/lib
. - For other install types of Postgres, look for the lib directory inside the Postgress install directory, e.g., for Postgress.app, find the lib directory in
/Applications/Postgres.app/Contents/MacOS/lib
, - for brew somewhere in
/usr/local/Cellar
, - on *nix, wherever your install is. But see first on *nix if your distro has later versions just through the package manager.
- 如果您使用的是 OSX 并安装了 Postgres 的 Enterprise DB 版本,这将在
/Library/PostgreSQL/9.2/lib
. - 对于其他安装类型的 Postgres,在 Postgress 安装目录中查找 lib 目录,例如,对于 Postgress.app,在 中找到 lib 目录
/Applications/Postgres.app/Contents/MacOS/lib
, - 酿造某处
/usr/local/Cellar
, - 在 *nix 上,无论您安装在哪里。但是,如果您的发行版仅通过包管理器具有更高版本,请首先在 *nix 上查看。
First copy the latest of these two libs from the Postgres lib directory to /usr/lib
:
首先将这两个库中最新的从 Postgres lib 目录复制到/usr/lib
:
sudo cp /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
sudo cp /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib
Then update (or create) the /usr/lib symlinks for this libs. Either way the command is ln -fs
:
然后更新(或创建)此库的 /usr/lib 符号链接。无论哪种方式,命令都是ln -fs
:
sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
Should be fixed. Pretty sure ln -fs is better than deleting the symlink and remaking it, so there is less chance of libssl being unfindable by something that needs it for the time it is not present (it does the same thing; it first deletes the symlink if it's already there, just faster than you can type it). Always wary of messing around on /usr/lib.
应该是固定的。很确定 ln -fs 比删除符号链接并重新制作它要好,因此在 libssl 不存在时需要它的东西找不到 libssl 的可能性较小(它做同样的事情;它首先删除符号链接,如果它是已经在那里了,只是比你输入的速度快)。始终警惕在 /usr/lib 上乱搞。
回答by Tupy
Worked for me:
对我来说有效:
env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib
-L/usr/local/opt/readline/lib' pip install psycopg2
回答by Robert Lujo
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:
在 OSX 10.11 上,El Capitan,报告替换符号链接的解决方案Operation not permitted
。对我有用的解决方案是使用 brew 并设置 DYLD_LIBRARY_PATH。所以:
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
找到 openssl brew libs 所在的位置(brew --prefix openssl
可以提供帮助),从目录开始搜索/usr/local/Cellar/openssl
。就我而言,它在/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 :
最后设置 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
UPDATE: More generic/better alternatives are (thanks to @dfrankow):
更新:更通用/更好的替代方案是(感谢@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
- 使用 brew 查找 openssl 位置(注意,brew 可能很慢):
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(brew --prefix openssl)/lib
- 出于开发目的,也许最好
DYLD_FALLBACK_LIBRARY_PATH
改用 - 检查这个
Restart shell, or just source ~/.bash_profile
, reinstall psycopg2:
重新启动 shell,或者只是source ~/.bash_profile
重新安装 psycopg2:
pip uninstall psycopg2
pip install psycopg2
and test if it works:
并测试它是否有效:
$ python -c"import psycopg2 ; print('psycopg2 is now ok')"
回答by eschipul
When trying to do a syncdb Postgres 9.1 and /psycopg2/_psycopg.so added a further error:
当尝试执行 syncdb Postgres 9.1 和 /psycopg2/_psycopg.so 时添加了进一步的错误:
Library not loaded: @loader_path/../lib/libcrypto.dylib Referenced from: /usr/lib/libpq.5.dylib Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libcrypto.0.9.8.dylib provides version 0.9.8
库未加载:@loader_path/../lib/libcrypto.dylib 引用自:/usr/lib/libpq.5.dylib 原因:库版本不兼容:libpq.5.dylib 需要 1.0.0 或更高版本,但需要 libcrypto。 0.9.8.dylib 提供 0.9.8 版本
Solved by copying these six (6) files from:
通过从以下位置复制这六 (6) 个文件来解决:
LOCAL:/Library/PostgreSQL/9.1/lib/
本地:/库/PostgreSQL/9.1/lib/
libssl.1.0.0.dylib
libssl.1.0.0.dylib
libssl.a
libssl.a
libssl.dylib
libssl.dylib
libcrypto.1.0.0.dylib
libcrypto.1.0.0.dylib
libcrypto.a
libcrypto.a
libcrypto.dylib
libcrypto.dylib
to: LOCAL:/usr/lib
到:本地:/usr/lib
This was on Mac OSx 10.8.1 with a web in a virtualenv (1.8.2) and pgAdmin (1.14.3). Inside the virtualenv is:
这是在 Mac OSx 10.8.1 上使用 virtualenv (1.8.2) 和 pgAdmin (1.14.3) 中的网络。在 virtualenv 里面是:
Django==1.4
姜戈==1.4
psycopg2==2.4.5
psycopg2==2.4.5
... etc... and now back to normal.
......等等......现在恢复正常。
回答by ytbryan
For me, the libcryto and libss version 1.0.0 resides below:
对我来说,libcryto 和 libss 版本 1.0.0 位于下面:
/Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib
/Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
so the commands that fix my problem is:
所以解决我的问题的命令是:
sudo ln -fs /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib
回答by Slack
my friend, just copy libssl.* files from PostgreSQL lib directory to /usr/lib and relaunch your application in this case all things will be perfect ^_^
我的朋友,只需将 libssl.* 文件从 PostgreSQL lib 目录复制到 /usr/lib 并重新启动您的应用程序,在这种情况下一切都会很完美^_^
回答by Lia
For me on Mavericks, it worked to just copy the two dylib and relaunch Python:
对于小牛队的我来说,只需复制两个 dylib 并重新启动 Python 即可:
cp /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib /usr/lib/
cp /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib /usr/lib/
回答by Justin Bailey
If you are uncomfortable copying libraries into your system directory, you can use the DYLD_LIBRARY_PATH environment variable to force the OS to search Postgres's library directory for libssl. E.g.:
如果您不喜欢将库复制到系统目录中,可以使用 DYLD_LIBRARY_PATH 环境变量来强制操作系统在 Postgres 的库目录中搜索 libssl。例如:
$ DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.4/lib pip install psycopg2
(documented under the dyld
man page).
(记录在dyld
手册页下)。
回答by chicha
I had similar problem on my Mac OS High Sierra.
我在 Mac OS High Sierra 上遇到了类似的问题。
ImportError: dlopen(/Users/chicha/Projects/CTMR/sample_registration/romans_env/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: /opt/local/lib/libssl.1.0.0.dylib
导入错误:dlopen(/Users/chicha/Projects/CTMR/sample_registration/romans_env/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2):库未加载:/opt/local /lib/libssl.1.0.0.dylib
But after "pip install postgres" it's work fine. According to pip show - "postgres is a high-value abstraction over psycopg2". While installing it's also installed psycopg2-binary and psycopg2-pool. So, all together they have repaired the situation somehow.
但是在“pip install postgres”之后它工作正常。根据 pip show - “postgres 是对 psycopg2 的高价值抽象”。安装时还安装了 psycopg2-binary 和 psycopg2-pool。所以,他们一起以某种方式修复了这种情况。