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
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
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:
go into a directory where you store your sources:
cd ~/src
download pycrypto source archive:
curl -o pycrypto.tar.gz "https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.tar.gz#md5=88dad0a270d1fe83a39e0467a66a22bb"
uncompress + untar archive:
gunzip pycrypto.tar.gz tar xvf pycrypto.tar
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With