简体   繁体   English

python pip install psycopg2安装报错

[英]python pip install psycopg2 install error

I did a simple pip install psycopg2 on mac system.我在 mac 系统上做了一个简单的pip install psycopg2 It installed fine, but when I try to use psycopg2 I get the error:它安装正常,但是当我尝试使用 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. pip freeze显示psycopg2==2.4.5恰到好处。 I have installed psycopg2 on several virtualenvs but this is the first time I am seeing such error.我已经在几个 virtualenvs 上安装了 psycopg2,但这是我第一次看到这样的错误。 I tried uninstalling and reinstalling, same results.我尝试卸载并重新安装,结果相同。 Please help请帮忙

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 (?)).这里接受的答案是正确的(除了我认为它必须是 ln -fs,事实上我认为如果不是(?),它甚至可能会破坏你的操作系统)。 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.在遇到这个问题并处理它之后,我只想收集这个问题的完整解决方案和其他 lib 问题(libcrypto.1.0.0.dylib),您将在 Mountain Lion 和 Snow Leopard 上遇到 Postgres 9.*,并且也许其他系统。 This also blocked me from running psql, which complained about the same two libs.这也阻止了我运行 psql,它抱怨相同的两个库。

Essentially there are two later-version libs needed in /usr/lib , libssl and libcrypto.基本上/usr/lib中需要两个更高版本的库,即 libssl 和 libcrypto。 You can find the needed versions of these libs in the Postgres lib directory.您可以在 Postgres lib 目录中找到这些库的所需版本。

  • If you're OSX and installed the Enterprise DB version of Postgres this will be in /Library/PostgreSQL/9.2/lib .如果你是 OSX 并且安装了 Postgres 的企业数据库版本,这将在/Library/PostgreSQL/9.2/lib中。
  • For other install types of Postgres, look for the lib directory inside the Postgress install directory, eg, for Postgress.app, find the lib directory in /Applications/Postgres.app/Contents/MacOS/lib ,对于其他安装类型的 Postgres,在 Postgress 安装目录中查找 lib 目录,例如,对于 Postgress.app,在/Applications/Postgres.app/Contents/MacOS/lib中查找 lib 目录,
  • for brew somewhere in /usr/local/Cellar ,对于/usr/local/Cellar某处的 brew,
  • on *nix, wherever your install is.在 *nix 上,无论你安装在哪里。 But see first on *nix if your distro has later versions just through the package manager.但是,如果您的发行版仅通过包管理器具有更高版本,请先在 *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.然后更新(或创建)这个库的 /usr/lib 符号链接。 Either way the command is ln -fs :无论哪种方式,命令都是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).很确定 ln -fs 比删除符号链接并重新制作它更好,因此 libssl 在它不存在时被需要它的东西找不到的可能性较小(它做同样的事情;它首先删除符号链接,如果它是已经在那里,只是比你输入它的速度快)。 Always wary of messing around on /usr/lib.始终警惕在 /usr/lib 上乱搞。

Worked for me:为我工作:

env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib
-L/usr/local/opt/readline/lib' pip install psycopg2

Source: Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7资料来源: 无法在 Mac OS X 10.7 上的 virtualenv 中使用 pip 安装 psycopg2

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实际上是指向最新版本库的软链接。

Eg, 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.根据Purrell 的回答,确保在使用ln命令时包含-fs标志,这有助于确保库不会在短时间内丢失。 Eg,例如,

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

On OSX 10.11, El Capitan, solution with replacing symlinks reported Operation not permitted .在 OSX 10.11 上,El Capitan,替换符号链接的解决方案报告Operation not permitted Solution that worked for me was using brew and setting up DYLD_LIBRARY_PATH.对我有用的解决方案是使用 brew 并设置 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 .找到 openssl brew 库所在的位置( brew --prefix openssl可以提供帮助),从目录/usr/local/Cellar/openssl开始搜索。 In my case it is in /usr/local/Cellar/openssl/1.0.2d_1/lib在我的例子中,它在/usr/local/Cellar/openssl/1.0.2d_1/lib

Finally set up DYLD_LIBRARY_PATH, ie 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使用 brew 查找 openssl 位置(注意,brew 可能很慢): 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出于开发目的,也许最好改用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')"

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).这是在 Mac OSx 10.8.1 上,在 virtualenv (1.8.2) 和 pgAdmin (1.14.3) 中有一个 web。 Inside the virtualenv is: virtualenv 内部是:

Django==1.4 Django==1.4

psycopg2==2.4.5 psycopg2==2.4.5

... etc... and now back to normal. ...等...现在恢复正常。

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

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 并重新启动您的应用程序,在这种情况下一切都会完美 ^_^

For me on Mavericks, it worked to just copy the two dylib and relaunch Python:对于我在 Mavericks 上,只需复制两个 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/

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.如果您不愿意将库复制到系统目录中,可以使用 DYLD_LIBRARY_PATH 环境变量强制操作系统在 Postgres 的库目录中搜索 libssl。 Eg:例如:

$ DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.4/lib pip install psycopg2

(documented under the dyld man page). (记录在dyld手册页下)。

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.但是在“pip install postgres”之后它工作正常。 According to pip show - "postgres is a high-value abstraction over psycopg2".根据 pip show - “postgres 是对 psycopg2 的高价值抽象”。 While installing it's also installed psycopg2-binary and psycopg2-pool.安装时还安装了 psycopg2-binary 和 psycopg2-pool。 So, all together they have repaired the situation somehow.所以,他们一起以某种方式修复了这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM