Pycrypto install fatal error: gmp.h file not found
似乎有很多人都有类似的问题,但是,经过大量的搜索,我还没有找到一个适合我的特定体系结构的解决方案。我正试图安装pycrypto(作为fabric的子公司),但没有用。
我运行的是mac10.8.2、homebrew版的python 2.7.3和xcode 4.6——使用pip或easy-install安装(我已经尝试了这两种方法)。据我所知,问题可能与我的Xcode版本有关,也可能与我的库有关。Xcode的命令行工具已经安装,我尝试将
无论我尝试什么角度,误差总是相同的(见下文)。任何帮助都将不胜感激。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /usr/local/share/python% pip install pycrypto Downloading/unpacking pycrypto Running setup.py egg_info for package pycrypto Installing collected packages: pycrypto Running setup.py install for pycrypto building 'Crypto.PublicKey._fastmath' extension /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -pipe -mmacosx-version-min=10.8 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -Wno-unused-value -Wno-empty-body -Qunused-arguments -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/_fastmath.c -o build/temp.macosx-10.8-intel-2.7/src/_fastmath.o src/_fastmath.c:36:11: fatal error: 'gmp.h' file not found # include <gmp.h> ^ 1 error generated. error: command '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' failed with exit status 1 Complete output from command /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c"import setuptools;__file__='/var/folders/ym/v8l23q_x2xz_qhx3m84n6ym00005fr/T/pip-build/pycrypto/setup.py';exec(compile(open(__file__).read().replace(' ', ' '), __file__, 'exec'))" install --record /var/folders/ym/v8l23q_x2xz_qhx3m84n6ym00005fr/T/pip-Xb7nGV-record/install-record.txt --single-version-externally-managed: running install running build running build_py running build_ext running build_configure building 'Crypto.PublicKey._fastmath' extension /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -pipe -mmacosx-version-min=10.8 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -Wno-unused-value -Wno-empty-body -Qunused-arguments -fwrapv -Wall -Wstrict-prototypes -std=c99 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/ -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/_fastmath.c -o build/temp.macosx-10.8-intel-2.7/src/_fastmath.o src/_fastmath.c:36:11: fatal error: 'gmp.h' file not found # include <gmp.h> ^ 1 error generated. error: command '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /usr/bin/clang' failed with exit status 1 ---------------------------------------- Command /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -c"import setuptools;__file__='/var/folders/ym/v8l23q_x2xz_qhx3m84n6ym00005fr/T/pip-build/pycrypto/setup.py';exec(compile(open(__file__).read().replace(' ', ' '), __file__, 'exec'))" install --record /var/folders/ym/v8l23q_x2xz_qhx3m84n6ym00005fr/T/pip-Xb7nGV-record/install-record.txt --single-version-externally-managed failed with error code 1 in /var/folders/ym/v8l23q_x2xz_qhx3m84n6ym00005fr/T/pip-build/pycrypto Storing complete log in /Users/me/.pip/pip.log |
尝试调用Fabric时出错:
1 2 3 4 5 6 7 8 9 10 | Traceback (most recent call last): File"/usr/local/share/python/fab", line 5, in <module> from pkg_resources import load_entry_point File"/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg/pkg_resources.py", line 2815, in <module> working_set.require(__requires__) File"/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg/pkg_resources.py", line 690, in require needed = self.resolve(parse_requirements(requirements)) File"/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.28-py2.7.egg/pkg_resources.py", line 588, in resolve raise DistributionNotFound(req) pkg_resources.DistributionNotFound: pycrypto>=2.1,!=2.4 |
如果您使用自制啤酒,这应该可以做到:
1 2 | brew install gmp env"CFLAGS=-I/usr/local/include -L/usr/local/lib" pip install pycrypto |
使用env将确保它只在这次工作。如果以后需要在另一个会话中安装pycrypto,请改为导出变量。
1 2 | export"CFLAGS=-I/usr/local/include -L/usr/local/lib" pip install pycrypto |
我可以使用以下命令安装pycrypto:
1 | CFLAGS=-I/opt/local/include pip install pycrypto |
我通过macports安装了gmp,运行在osx 10.8.3上,python.org上的python 2.7.2。在本例中,我将安装到virtualenv中。
使用pycrypto时,我确实会收到以下警告,但它仍然有效:
1 2 | /Users/me/.virtualenvs/blah/lib/python2.7/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability. _warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning) |
简单地链接gmppylib没有帮助,因为pycrpto需要编译一些包含gmp.h的C文件。您应该安装gmp库,其中包含gmp.h。似乎您必须在Mac操作系统上安装gmp。以下两个链接应该对您有所帮助。
- 在Mac OS X上安装gmp和mpfr
- 使用Xcode在MacOS X上安装gmp
我终于意识到我问题的根源在于Fabric和Pypcrypto版本之间的不兼容。一旦我将我的fabric版本降到1.2.6,我就不再得到上面的错误。然后,我用这个教程作为起点。但是,尽管有教程和旧版本的fabric,我还是得到了
以下是对我有效的修复方法:
https://medium.com/software-bugs/84afab886a1e
您需要基于安装头include path(-i)创建一个symlink,但是会崩溃。例子:
正在生成"crypto.publickey.u fastmath"扩展
/applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/clang-fno严格别名-fno common-dynamic-pipe-march=native-mmacosx version min=10.7-isysroot/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.7.sdk-issystem/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.7.sdk/usr/include-i/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.7.sdk/usr/include-i/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.7.sdk/usr/x11/include-wno未使用的值-wno空体-qunussed参数-fwrapv-wall-wstrict原型-std=c99-o3-fomit帧指针-i src/*-i/usr/include/-*i/usr/local/cellor/python/2.7.3/frameworks/python.framework/versions/2.7/include/python2.7-c src/fastmath.c-o build/temp.macosx-10.7-x86_-2.7/src/fastmath.o
src/_fastmath.c:36:11:致命错误:找不到"gmp.h"文件