tsc*_*zle 87 python postgresql psycopg2
我运行"sudo pip install psycopg2",我得到一堆看起来像的输出
cc -DNDEBUG -g -fwrapv -Os .....
.....
cc -DNDEBUG -g -fwrapv -Os .....
.....
Run Code Online (Sandbox Code Playgroud)
最后它说:
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
Run Code Online (Sandbox Code Playgroud)
运行easy_install或从源代码执行它都会在最后给出同样的错误(关于-lssl找不到库的部分).
运行brew安装(或升级)openssl会产生以下结果
$ brew upgrade openssl
Error: openssl-1.0.1h already installed
Run Code Online (Sandbox Code Playgroud)
谁能帮我吗?
sas*_*sas 216
对于在macOS Sierra 10.12上寻找解决方案的人:我通过安装命令行工具修复了这个问题:
xcode-select --install
Run Code Online (Sandbox Code Playgroud)
在那之后,pip install psycopg2
应该工作.
如果没有,你也可以尝试链接brew的openssl:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
Run Code Online (Sandbox Code Playgroud)
通过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
Run Code Online (Sandbox Code Playgroud)
正如@macho指出如果这仍然不起作用,你可能需要使用--no-cache
pip选项,例如
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install psycopg2
Run Code Online (Sandbox Code Playgroud)
小智 28
使用 MacOS Catalina 10.15.4,以下是唯一对我有用的命令:
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
Run Code Online (Sandbox Code Playgroud)
And*_*rie 19
运行时,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
Run Code Online (Sandbox Code Playgroud)
遵循这个建议这里是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"
Run Code Online (Sandbox Code Playgroud)
Ash*_*gal 19
我从brew(brew install openssl
)安装了OpenSSL
以下为我工作:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip install psycopg2
Run Code Online (Sandbox Code Playgroud)
Kho*_*Ngo 19
MacOS 12 Monterey - M1 芯片组的解决方案:
xcode-select --install
brew install openssl
echo 'export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"' >> ~/.zshrc
echo 'export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/opt/openssl@3/lib/' >> ~/.zshrc
Run Code Online (Sandbox Code Playgroud)
小智 15
适用于 MacOS BigSur 的解决方案(2021 年 5 月)
我也有类似的问题。但就在我把电脑从办公桌上扔掉之前,我找到了一个在 MacOS BigSur 上适用的解决方案:
我的 OpenSSL 安装已损坏。
brew reinstall openssl
Run Code Online (Sandbox Code Playgroud)
重新安装完成后会弹出3条需要执行的命令:
命令如下所示:
不要只是复制
echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
Run Code Online (Sandbox Code Playgroud)
这对我有用!不能保证这也适合您。
brew reinstall可能不是最好的解决方案,但它有效并提供了必要的命令。
Isa*_*lip 11
对我有用的是链接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
Run Code Online (Sandbox Code Playgroud)
McF*_*izz 10
如果你:
psycopg2
在 Python 内部venv
并且psycopg2
在 Apple Silicon(新 ARM CPU)上然后,正如 IamAshay 在他们的回答中指出的那样,我们需要导出一些变量以指向我们的 OpenSSL 安装。
Apple Silicon 上的安装目录显然与 Apple Intel 机器不同。无论如何,要查找系统上 OpenSSL 的安装位置(通过自制程序),您可以运行
brew --prefix openssl
Run Code Online (Sandbox Code Playgroud)
就我而言,我们有/opt/homebrew/opt/openssl@1.1
. 所以这意味着我们需要导出的变量是
export LDFLAGS="-L/opt/homebrew/opt/openssl/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl/include"
Run Code Online (Sandbox Code Playgroud)
然后我们就可以运行
pip install psycopg2
Run Code Online (Sandbox Code Playgroud)
这是新的macOs版本的问题,pip不能安装cryptography
。解决我的问题的是向安装命令提供 env :
brew install openssl
env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" <YOUR COMMAND HERE>
Run Code Online (Sandbox Code Playgroud)
您可以替换<YOUR COMMAND HERE>
为pip install cryptography
, 或者pip install <SOMETHING THAT REQUIRES cryptography>
例如。
归功于本文:修复 macOS Sierra 致命错误:找不到“openssl/opensslv.h”或“openssl/aes.h”文件
在莫哈韦沙漠,我将它们添加到.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"
Run Code Online (Sandbox Code Playgroud)
然后能够在python 3.7.4 virtualenv中安装psycopg 2.8.3。
重新安装xcode和命令行工具之后。
以上所有答案都对您有所帮助!
小智 -5
我已经设法通过使用来修复它:
brew unlink openssl && brew link openssl --force
Run Code Online (Sandbox Code Playgroud)
我不确定这与我之前在 OpenSSL 上所做的尝试中进行的 brew 卸载/升级有何不同。我的假设是这些操作留下了一些“错误”的共享库,这些库阻止了它的工作。请注意,这也解决了安装 python 加密模块的问题。
归档时间: |
|
查看次数: |
18007 次 |
最近记录: |