Pycrypto install fatal error: gmp.h file not found

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

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)

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