16

I'm running a CentOS 6.4 server with Python 2.7 (installed via PythonBrew script)

I have gmp installed via 'yum install gmp' and python-devel installed via 'yum install python-devel' (but it's for python 2.6 series)

I'm trying to install pycrypto on my server, but it's giving me

warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath

Is there any way to make pip 'recognize' my gmp installation?

Thanks : D

user269334
  • 499
  • 1
  • 6
  • 13

5 Answers5

9

I got the above error when trying to install Fabric at the system level on Centos 6.4 using pip. (Fabric uses pycrypto).

warning: GMP or MPIR library not found; Not building Crypto.PublickKey._fastmath

This is how I got it working:

yum install gmp-devel
sudo pip uninstall ecdsa pycrypto paramiko fabric 
# clear out the pip build dirs
rm -rf /tmp/pip-*
# make sure the directory containing libgmp.so.3 is on the python path
export LD_LIBRARY_PATH="/usr/lib64:$LD_LIBRARY_PATH"  
pip install fabric 
Joe J
  • 8,079
  • 8
  • 57
  • 84
7

Here is a step-by-step I've just made up on my CentOS server (the sequence assumes you're not root):

LIBGMP INSTALL

Firstly, setup and install libgmp somewhere in your home directory, as follows:

./configure prefix=$HOME
make
make install prefix=$HOME

This will create a ~/lib, a ~/include and a ~/share directory if not existing already.

Then, add the following line to your .bashrc:

export LD_LIBRARY_PATH=$HOME/lib:/usr/local/lib:$LD_LIBRARY_PATH

Do a ". ~/.bashrc" to enforce your changes.

PYCRYPTO BUILD & INSTALL

We need to deal with the install process manually. Firstly, we may download pycrypto as follows:

Then we need to cheat the configuration "a bit":

cd pycrypto-26
./configure --includedir=$HOME/include
  • Edit the file cd src/config.h and amend the values for the definitions:

    #define HAVE_DECL_MPZ_POWM 0 instead of 1

    #define HAVE_DECL_MPZ_POWM_SEC 1 instead of 0

    #define HAVE_LIBGMP 1 instead of 0

  • Then edit the setup.py file by searching for the keyword "_fastmath" and ensure that the Extension() declaration looks as per below:

    Extension("Crypto.PublicKey._fastmath",
              include_dirs=['/home/<yourhome>/include','src/','/usr/include/'],
              library_dirs=['/home/<yourhome>/lib'],
              libraries=['gmp'],
              sources=["src/_fastmath.c"]),
    

Finally, build pycrypto with:

python setup.py build

You should see somewhere in the trace the following line:

...
building 'Crypto.PublicKey._fastmath' extension
...

You can then do a "python setup.py install" or, if like me you prefer pip:

cd ..
pip install ./pycrypto-2.6

Then you should get no error when executing the following lines from python:

>>> from Crypto.PublicKey import _fastmath
>>> import Crypto.Random
>>> _fastmath.HAVE_DECL_MPZ_POWM_SEC
1
lai
  • 875
  • 9
  • 13
5

You probably need gmp-devel installed, too. This gives pycrypto the headers it needs to build using libgmp.

On Ubuntu, I only had libgmp10 installed. I hit the same warning when trying to install pycrypto. After installing the Ubuntu package libgmp-dev, the warning went away and the build script indicated it was using the _fastmath extension.

If you already installed pycrypto without _fastmath, you can reinstall it with the -I flag, e.g.

sudo pip install -I pycrypto

Paul
  • 231
  • 2
  • 9
3

Just for anyone who runs across this in recent years, as I am sure there are/will be some. I was able to easily fix this issue on my Debian Jessie install by running the following command.

$ sudo apt-get install python-dev

Then try your install again. In my case I was trying to install ansible via pip with the following command. Also for those to be able to come across this post with same scenario.

$ sudo pip install ansible

The output should now be the following.

Successfully installed pycrypto
Cleaning up...

I hope this helps someone down the road! - justin

0

You are missing the C++ libraries to build this. Install VS 2017 https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017

advdev
  • 1
  • 2