问题:安装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
谁能帮我吗?
I run
sudo pip install psycopg2
and I get a bunch of output that looks like:
cc -DNDEBUG -g -fwrapv -Os .....
.....
cc -DNDEBUG -g -fwrapv -Os .....
.....
And at the end it says:
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
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).
Running brew install (or upgrade) openssl yields the below
$ brew upgrade openssl
Error: openssl-1.0.1h already installed
Can anyone help me out?
回答 0
对于在macOS Sierra 10.12(或更高版本,最有可能)上寻求解决方案的用户:我通过安装命令行工具来解决此问题:
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 e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
正如@macho在下面指出的,如果这仍然不起作用,则可能需要使用--no-cache
pip选项,例如
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install psycopg2
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
After that, pip install psycopg2
should work.
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
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
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
回答 1
我从brew(brew install openssl
)安装了OpenSSL
以下为我工作:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip install psycopg2
I had OpenSSL installed from brew (brew install openssl
)
The following worked for me:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip install psycopg2
回答 2
运行时,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 e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
遵循此建议,这是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"
When running brew link openssl
I get the following message:
$ 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 e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
Following this advice here’s the pip
command you need to use:
$ 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"
回答 3
对我有用的是命令中提供的链接openssl的提示,
$ brew link openssl
Warning: Refusing to link macOS-provided software: openssl
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ pip install psycopg2
Collecting psycopg2
Using cached https://files.pythonhosted.org/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.8.2
What worked for me was the hint provided in the command to link openssl,
$ brew link openssl
Warning: Refusing to link macOS-provided software: openssl
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ pip install psycopg2
Collecting psycopg2
Using cached https://files.pythonhosted.org/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.8.2
回答 4
在莫哈韦沙漠,我将它们添加到.bash_profile
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/curl/lib -L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/curl/include -I/user/local/opt/openssl/include"
然后能够在python 3.7.4 virtualenv中安装psycopg 2.8.3。
重新安装xcode和命令行工具后。
以上所有答案都对您有所帮助!
On mojave I added these to the .bash_profile
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/curl/lib -L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/curl/include -I/user/local/opt/openssl/include"
was then able to install psycopg 2.8.3 in a python 3.7.4 virtualenv.
This after reinstalling xcode and the command line tools.
All the answers above helped!
回答 5
使用MacOS Catalina 10.15.4,以下是对我有用的唯一命令:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
With MacOS Catalina 10.15.4, the following was the only command that worked for me:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
回答 6
这是新的macOs版本的问题,其中pip无法安装cryptography
。解决我的问题的是将env提供给install命令:
brew install openssl
env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" <YOUR COMMAND HERE>
您可以<YOUR COMMAND HERE>
用pip install cryptography
或替换pip install <SOMETHING THAT REQUIRES cryptography>
。
归功于本文:修复macOS Sierra致命错误:找不到“ openssl / opensslv.h”或“ openssl / aes.h”文件
This’s the problem of new macOs version, where pip cannot install cryptography
. What fixed my problem is to provide the env to the install command:
brew install openssl
env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" <YOUR COMMAND HERE>
You can replace <YOUR COMMAND HERE>
with pip install cryptography
, or pip install <SOMETHING THAT REQUIRES cryptography>
for example.
Credit to this article: Fixing macOS Sierra fatal error: ‘openssl/opensslv.h’ or ‘openssl/aes.h’ file not found
回答 7
在使用Homebrew安装OpenSSL之后,以下两个命令使用Fish帮我解决了此问题。
set -gx LDFLAGS "-L/usr/local/opt/openssl/lib"
set -gx CPPFLAGS "-I/usr/local/opt/openssl/include"
使用brew info openssl
之后,可以获取最新信息。
Using Fish, the following two commands solved this issue for me after installing OpenSSL with Homebrew.
set -gx LDFLAGS "-L/usr/local/opt/openssl/lib"
set -gx CPPFLAGS "-I/usr/local/opt/openssl/include"
Use brew info openssl
to get up-to-date info.
回答 8
最近在High Sierra中出现了此问题,刚刚在virtualenv中安装了Python 3.7。
解决方案是使用更高版本的psycopg2。版本2.7.7有效,而版本2.7.1无效。
Recently had this problem in High Sierra, having just installed Python 3.7 in a virtualenv.
The solution is to use a later version of psycopg2. Version 2.7.7 worked, where 2.7.1 did not.
回答 9
而不是同一作者的psycopg2
install,install psycopg2-binary
:
pip install psycopg2-binary
这是文档关于此PyPI软件包的说明:
您可以通过从PyPI安装psycopg2-binary软件包来获取不需要编译器或外部库的独立软件包:
$ pip install psycopg2-binary
二进制软件包是开发和测试的实际选择,但在生产中,建议使用从源构建的软件包。
Instead of installing psycopg2
, install psycopg2-binary
, from the same authors:
pip install psycopg2-binary
This is what the documentation says about this PyPI package:
You can […] obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary package from PyPI:
$ pip install psycopg2-binary
The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.
回答 10
回答 11
我安装了cython后遇到了同样的错误,并解决了这个问题
I had this same error and got it to resolve after I pip installed cython
回答 12
从conda环境运行PyCharm,使用以下方法解决了我的问题:
--> conda install psycopg2
The following packages will be UPDATED: ...
...
Proceed ([y]/n)?
--> y
--> pip3 install psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.8.4
'''
Running PyCharm from conda environment, solved my issue using:
--> conda install psycopg2
The following packages will be UPDATED: ...
...
Proceed ([y]/n)?
--> y
--> pip3 install psycopg2
Installing collected packages: psycopg2
Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.8.4
'''
回答 13
我使用MacPorts安装了OpenSSL,因此目录与Brew不同。
sudo port install openssl
我通过执行以下操作找到了目录:
port contents openssl | grep lib
port contents openssl | grep include
然后我导出变量:
export LDFLAGS="-L/opt/local/lib"
export CPPFLAGS="-I/opt/local/include/openssl"
您可能还必须:
xcode-select --install
I installed OpenSSL using MacPorts therefore directories are not like those of Brew.
sudo port install openssl
I found the directories by doing:
port contents openssl | grep lib
port contents openssl | grep include
Then I exported the variables:
export LDFLAGS="-L/opt/local/lib"
export CPPFLAGS="-I/opt/local/include/openssl"
You might also have to:
xcode-select --install
回答 14
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
为我工作
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
worked for me
回答 15
我设法通过使用以下方法修复了该问题:
brew unlink openssl && brew link openssl --force
我不确定这与之前尝试在OpenSSL上进行的brew卸载/升级有何不同。我的假设是,这些操作留下了一些“错误的”共享库,这些库无法正常工作。请注意,这还解决了安装python加密模块的问题。
I’ve managed to fix it by using:
brew unlink openssl && brew link openssl --force
I am not sure how this differs from the brew uninstall/upgrades that I did on OpenSSL in prior attempts I’ve made. My assumption is that these operations left some of the “faulty” shared libraries which were preventing this from working. Note that this also fixed issues with installing python cryptography module.