【问题标题】:Pycrypto install fatal error: gmp.h file not foundPycrypto 安装致命错误:找不到 gmp.h 文件
【发布时间】:2013-02-28 18:56:20
【问题描述】:

似乎有很多人遇到过类似的问题,但是,经过大量搜索后,我无法找到适用于我的特定架构的解决方案。我试图安装 Pycrypto(作为 Fabric 的子公司)无济于事。

我正在通过 Homebrew 运行 Mac 10.8.2、python 2.7.3 和 XCode 4.6——使用 pip 或 easy_install 安装(我都尝试过)。据我所知,问题可能与我的 XCode 版本有关,也可能与我的库有关。 XCode 的命令行工具已安装,我尝试将setenv ARCHFLAGS "-arch i386 -arch x86_64" 放在我的 .cshrc 文件中。我也试过ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer。至于图书馆,我尝试通过ln -s /usr/local/lib/libgmp.dylib /usr/lib/libgmp.dylib 链接它们——但这也没有用。

无论我尝试什么角度,错误总是相同的(见下文)。任何和所有的帮助将不胜感激。

/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('\r\n', '\n'), __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('\r\n', '\n'), __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 时的错误:

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

【问题讨论】:

  • 我发现brew uninstall gmp ; brew install gmp 为我解决了这个问题。

标签: python osx-mountain-lion gmp pycrypto


【解决方案1】:

如果您使用 Homebrew,这应该可以解决问题:

brew install gmp
env "CFLAGS=-I/usr/local/include -L/usr/local/lib" pip install pycrypto

使用 env 只会使它适用于该调用。如果您需要稍后在此会话中安装 pycrypto,请导出该变量。

export "CFLAGS=-I/usr/local/include -L/usr/local/lib" 
pip install pycrypto

【讨论】:

  • 谢谢。 env "CFLAGS=-I/usr/include/gmp -L/usr/lib/gmp" pip install pycrypto 在 Solaris 11.3 上为我工作。
  • 为我工作 - 唯一的选择。
  • 您认为它的便携性如何?如果我在例如运行相同的更改,你认为它会破坏任何东西吗?森托斯? (我在脚本内部运行pip install。)
【解决方案2】:

我能够使用以下命令安装 PyCrypto:

CFLAGS=-I/opt/local/include pip install pycrypto

我通过 MacPorts 安装了 GMP,在 OSX 10.8.3 上运行 Python 2.7.2,来自 python.org。在这种情况下,我将安装到 virtualenv 中。

使用 PyCrypto 时,我确实收到以下警告,但它仍然有效:

/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)

【讨论】:

  • 我还需要将 -L/usr/local/lib 添加到 CFLAGS。在卡塔利娜。
【解决方案3】:

这是对我有用的修复:

https://medium.com/software-bugs/84afab886a1e

您需要根据安装头包含路径(-I)创建符号链接但崩溃。示例:

构建“Crypto.PublicKey._fastmath”扩展

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fno-strict-aliasing -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 -isystem /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-unused-value -Wno-empty-body -Qunused-arguments -fwrapv -Wall -Wstrict-原型 -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.7-x86_64-2.7/src/_fastmath.o

src/_fastmath.c:36:11:致命错误:找不到“gmp.h”文件

【讨论】:

    【解决方案4】:

    我终于意识到问题的根源在于 Fabric 和 Pycrypto 版本之间的不兼容。一旦我将我的 Fabric 版本降级到 1.2.6,就不再出现上述错误。然后,我使用tutorial 作为起点。但是,尽管有教程和旧版本的 Fabric,我仍然收到 PyCrypto &gt;= 2.1, !=2.4 错误。我最终从源代码安装了 Pycrypto 2.2(因为显然 pip 只会安装 v.2.0.1,即使指定 pip -Iv install pycrypto==2.2this 和 v.2.6 导致 gmp.h 错误)。最后,一切正常。

    【讨论】:

      【解决方案5】:

      简单地链接 gmppylib 是没有帮助的,因为 pycrpto 需要编译一些包含 gmp.h 的 C 文件。您应该安装了包含 gmp.h 的 GMP 库。看来您必须在 Mac OS 上安装 GMP。以下两个链接应该对您有所帮助。

      【讨论】:

        猜你喜欢
        • 2016-06-17
        • 2018-09-01
        • 2022-06-20
        • 2014-05-13
        • 2016-03-13
        • 1970-01-01
        • 1970-01-01
        • 2019-03-11
        • 2019-05-01
        相关资源
        最近更新 更多