安装psycopg2时出错,找不到-lssl的库

我运行“sudo pip install psycopg2”,我得到了一堆类似的输出

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('\r\n', '\n'), __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找不到库的部分)。


运行brew安装(或升级)openssl会产生下面的结果

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

谁能帮我吗?

对于任何在macOS Sierra 10.12上寻找解决scheme的人:我通过安装命令行工具来解决这个问题:

 xcode-select --install 

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

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

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

通过brew安装openssl。 请注意, brew link openssl --force不再工作:

 $ 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 eg: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib 

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

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

当运行brew link openssl我得到以下消息:

 $ brew link openssl 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 eg: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib 

遵循这个build议,你需要使用pip命令:

 $ pip install -r requirements.txt --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib" 

我已经设法解决它通过使用:

 brew unlink openssl && brew link openssl --force 

我不确定这与我之前尝试过的在OpenSSL上进行的brew卸载/升级有什么不同。 我的假设是,这些操作留下了一些“错误的”共享库,这阻止了这个工作。 请注意,这也解决了安装python密码模块的问题。