Pycrypto install fatal error: gmp.h file not found

前端 未结 5 1331
抹茶落季
抹茶落季 2021-01-31 07:43

It seems like there are a number of people who have had a similar problem, however, after much searching I haven\'t been able to find a solution that works with my particular ar

相关标签:
5条回答
  • 2021-01-31 08:23

    If you use Homebrew, this should do the trick:

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

    Using env will only make it work for that invocation. If you need to install pycrypto at a later time in this session export the variable instead.

    export "CFLAGS=-I/usr/local/include -L/usr/local/lib" 
    pip install pycrypto
    
    0 讨论(0)
  • 2021-01-31 08:26

    I was able to get PyCrypto to install using the following command:

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

    I have GMP installed via MacPorts, running on OSX 10.8.3 with Python 2.7.2 from python.org. In this case I am installing into a virtualenv.

    I do get the following warning when PyCrypto is used, but it still works:

    /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)
    
    0 讨论(0)
  • 2021-01-31 08:41

    Simply linking gmppylib is not helpful because pycrpto needs to compile some C files which will include gmp.h. You should have the GMP library installed which will contain gmp.h. It seems you have to install GMP on your Mac OS. The following two links should be helpful to you.

    • Installation of gmp and mpfr on Mac OS X
    • Installing GMP on MacOS X with Xcode
    0 讨论(0)
  • 2021-01-31 08:41

    Here is the fix that worked for me:

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

    You need to create a symlink based on the installation header include path (-I) in but crash. Example:

    building 'Crypto.PublicKey._fastmath' extension

    /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-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.7-x86_64-2.7/src/_fastmath.o

    src/_fastmath.c:36:11: fatal error: 'gmp.h' file not found

    0 讨论(0)
  • 2021-01-31 08:44

    I finally realized that the root of my problem was in an incompatibility between the versions of Fabric and Pycrypto. Once I downgraded my version of Fabric to 1.2.6, I no longer got the errors above. Then, I used the tutorial as a jumping off point. However, despite the tutorial and the older version of Fabric, I still got the PyCrypto >= 2.1, !=2.4 error. I eventually installed Pycrypto 2.2 from source (since apparently pip will only install v. 2.0.1 even when designating pip -Iv install pycrypto==2.2 per this and v. 2.6 resulted in the gmp.h error). Finally, everything worked.

    0 讨论(0)
提交回复
热议问题