Python 尝试在 Mac OSX 小牛上安装 pycrypto
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19617686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trying to install pycrypto on Mac OSX mavericks
提问by
I am currently trying to install pycrypto and when I execute python setup.py build I receive this following error:
我目前正在尝试安装 pycrypto,当我执行 python setup.py build 时,我收到以下错误:
cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/_fastmath.o -lgmp -o build/lib.macosx-10.9-intel-2.7/Crypto/PublicKey/_fastmath.so
ld: illegal text-relocation to '___gmp_binvert_limb_table' in /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'cc' failed with exit status 1
I've already tried reinstalling the command line tools and removing old instances of Xcode.
我已经尝试重新安装命令行工具并删除旧的 Xcode 实例。
Any help would be great thanks
任何帮助都会非常感谢
回答by Chris Eldredge
I ran into the same issue and was able to fix it by installing gmp:
我遇到了同样的问题,并且能够通过安装 gmp 来修复它:
brew install gmp
Then I nuked my build directory and started over with the pycrypto install and it succeeded.
然后我修改了我的构建目录并重新开始安装 pycrypto 并且它成功了。
This also fixes the warning message during pycrypto's configure script:
这也修复了 pycrypto 的配置脚本期间的警告消息:
warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath
See related question.
请参阅相关问题。
回答by einnocent
Install homebrew(single line for installation at bottom of page), then try:
安装自制软件(页面底部的单行安装),然后尝试:
$ sudo pip install pycrypto
回答by domino
This worked for me. (Should work if you are on Xcode 5.1)
这对我有用。(如果您使用的是 Xcode 5.1,应该可以使用)
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pycrypto
回答by radiofrequency
This did it for me:
这为我做到了:
sudo port install gmp
sudo ln -s /opt/local/lib/libgmp.dylib /usr/lib/libgmp.dylib
ARCHFLAGS=-Wno-error CFLAGS=-I/opt/local/include sudo -E pip install pycrypto
回答by Guto Hernandes
If I'm not mistaken, pip and homebrew are both package managers, but homebrew is built on ruby and pip is built on python.
如果我没记错的话,pip 和 homebrew 都是包管理器,但是 homebrew 是建立在 ruby 上的,而 pip 是建立在 python 上的。
$ sudo pip install pycrypto
This command you referred to needs pip installed, not homebrew.
您提到的这个命令需要安装 pip,而不是自制软件。
回答by bbaassssiiee
I noticed recently that I needed brew to install gmpto get pip install pycrypto working again after upgrading OSX 10.9 and Xcode 5. But then the gmp build started failing on illegal text-relocation. It seems a known issue 12946causes the compiler to fail compiling position independent code:
我最近注意到,在升级 OSX 10.9 和 Xcode 5 后,我需要 brew 来安装 gmp以使 pip install pycrypto 再次工作。但是随后 gmp 构建开始因非法文本重定位而失败。似乎一个已知问题 12946导致编译器无法编译位置无关代码:
cc -bundle -undefined dynamic_lookup -Wl,-F. -Wno-error=unused-command-line-argument-hard-error-in-future -Wno-error=unused-command-line-argument-hard-error-in-future build/temp.macosx-10.9-intel-2.7/src/_fastmath.o -lgmp -o build/lib.macosx-10.9-intel-2.7/Crypto/PublicKey/_fastmath.so
ld: illegal text-relocation to '___gmp_binvert_limb_table' in /usr/local/lib/libgmp.a(mp_minv_tab.o) from '___gmpn_divexact_1' in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'cc' failed with exit status 1
cc -bundle -undefined dynamic_lookup -Wl,-F。-Wno-error=unused-command-line-argument-hard-error-in-future -Wno-error=unused-command-line-argument-hard-error-in-future build/temp.macosx-10.9-intel- 2.7/src/_fastmath.o -lgmp -o build/lib.macosx-10.9-intel-2.7/Crypto/PublicKey/_fastmath.so
ld:非法文本重定位到 /usr/local/lib/libgmp.a(mp_minv_tab.o) 中的 '___gmp_binvert_limb_table' 从 /usr/local/lib/libgmp.a(dive_1.o) 中的 '___gmpn_divexact_1' 用于架构 x86_64
clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
错误:命令“cc”失败,退出状态为 1
Similar to the answer provided by radiofrequencyI symlinked the shared library of gmp into the system's /usr/lib directory as a workaround:
类似于射频提供的答案,我将 gmp 的共享库符号链接到系统的 /usr/lib 目录中作为解决方法:
sudo ln -s /usr/local/Cellar/gmp/5.1.3/lib/libgmp.dylib /usr/lib/libgmp.dylib
The gmp developer should add --with-pic.
gmp 开发人员应该添加 --with-pic。
Side point: the number of warnings building pycrypto does not provide comfort.
旁注:构建 pycrypto 的警告数量并不能提供安慰。
回答by Nick Woodhams
For those of you also looking to install pycrypto as well as the cryptography package, this is the command that ended up working for me:
对于那些还希望安装 pycrypto 和加密包的人来说,这是最终对我有用的命令:
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography
env ARCHFLAGS="-arch x86_64" LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include" pip install cryptography
回答by Mullefa
I'm a new comer to python; I experienced this problem also; and it vexed me. None of the solutions posted worked for me, so I archived libgmp.a
and libgmp.la
temporarily, and pip
then installed Crypto
without error. Is this an acceptable approach? I have nounderstanding as to why this worked...
我是python的新手;我也遇到过这个问题;这让我很恼火。该解决方案中没有贴为我工作,所以我存档libgmp.a
和libgmp.la
暂时,并pip
再安装Crypto
没有错误。这是一种可以接受的方法吗?我不明白为什么这有效......
回答by thinkski
On Yosemite:
优胜美地:
CC=clang sudo -E pip install pycrypto
回答by Safronus
For installation of PyCrypto use MacPorts and following command. I tested it on the newest version of Mac OS X - Yosemite:
要安装 PyCrypto,请使用 MacPorts 和以下命令。我在最新版本的 Mac OS X - Yosemite 上对其进行了测试:
Python Version 2.7:
Python 2.7 版:
sudo port install py27-crypto
Python Version 3.4:
Python 3.4 版:
sudo port install py34-crypto