安装 psycopg2 时出错,找不到 -lssl 的库 [英] error installing psycopg2, library not found for -lssl

查看:48
本文介绍了安装 psycopg2 时出错,找不到 -lssl 的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跑

sudo pip install psycopg2

我得到了一堆看起来像这样的输出:

and I get a bunch of output that looks like:

cc -DNDEBUG -g -fwrapv -Os .....
.....
cc -DNDEBUG -g -fwrapv -Os .....
.....

最后它说:

ld: library not found for -lssl

clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: command 'cc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/bz/pvj1g9xj16d10pjjgbrfl3fw0000gn/T/pip_build_root/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('
', '
'), __file__, 'exec'))" install --record /var/folders/bz/pvj1g9xj16d10pjjgbrfl3fw0000gn/T/pip-uE3thn-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/var/folders/bz/pvj1g9xj16d10pjjgbrfl3fw0000gn/T/pip_build_root/psycopg2
Storing debug log for failure in /Users/Tyler/Library/Logs/pip.log

<小时>

运行 easy_install从源代码 都在最后给我同样的错误(关于 -lssl 找不到库的部分).


Running easy_install or doing it from source both give me the same error at the end (the part about library not found for -lssl).

运行 brew install(或升级)openssl 产生以下内容

Running brew install (or upgrade) openssl yields the below

$ brew upgrade openssl
Error: openssl-1.0.1h already installed

有人可以帮我吗?

推荐答案

对于在 macOS Sierra 10.12(或更高版本,最有可能)上寻找解决方案的任何人:我通过安装命令行工具解决了这个问题:

For anyone looking for a solution for this on macOS Sierra 10.12 (or later, most likely): I fixed this by installing the command line tools:

xcode-select --install

之后,pip install psycopg2 应该可以工作了.

After that, pip install psycopg2 should work.

如果没有,您也可以尝试链接到 brew 的 openssl:

If it doesn't, you could also try to link against brew's openssl:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2

通过 brew 安装 openssl.请注意,brew 链接 openssl --force 不再起作用:

with openssl installed via brew. Note that the brew link openssl --force does not work anymore:

$ brew link openssl --force                                                                                 17.5s
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
  -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

正如@macho 在下面指出的那样,如果这仍然不起作用,您可能需要使用 pip 的 --no-cache 选项,例如

As @macho points out below if this still does not work, you might need to use the --no-cache option of pip, e.g.

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install psycopg2

如果您例如在 ARM/Apple M1 Mac 上构建(因为 homebrew 安装在 /opt/homebrew/),请记住相应地调整这些路径;命令如下:

Remember to adjust these paths accordingly should you for instance build on ARM/Apple M1 Macs (as homebrew is installed at /opt/homebrew/); command as follows:

env LDFLAGS="-I/opt/homebrew/opt/openssl/include -L/opt/homebrew/opt/openssl/lib" pip --no-cache install psycopg2

这篇关于安装 psycopg2 时出错,找不到 -lssl 的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆