Installing M2Crypto on CentOS, RedHat or Fedora

on February 05, 2013 in technology about

Installing M2Crypto, a feature-rich Python wrapper for OpenSSL, should be a simple matter of running pip install M2Crypto. However, it seems that on CentOS, RedHat or other Fedora Core-based distributions, especially 32-bit operating system running on 64-bit hardware, it is a bit tricky.

Here are the requirements for the current version (0.21.1) taken from M2Crypto home page: Python 2.3+, OpenSSL 0.9.7+, SWIG 1.3.28+. Skimming through the INSTALL notes, we stumble on “Note about Fedora Core -based Distributions”:

Fedora Core (and RedHat, CentOS etc.) have made changes to OpenSSL configuration compared to many other Linux distributions. If you can not build M2Crypto normally, try the fedora_setup.sh script included with M2Crypto sources.”

Error with pip install M2Crypto on CentOS, RedHat or Fedora:

...
/usr/include/openssl/opensslconf.h:31: Error: CPP #error ""This openssl-devel package does not work your architecture?"". Use the -cpperraswarn option to continue swig processing.

error: command 'swig' failed with exit status 1

Okay, so it didn’t build normally. Let’s see if we can build it manually using fedora_setup.sh as recommened in the INSTALL notes.

With your virtualenv environment activated, the failed pip install M2Crypto above would have left behind the downloaded files in <your-virtualenv-path>/build/M2Crypto. If you don’t use virtualenv (you should!), you can download a copy of M2Crypto on Pypi.

Normally, going into this directory and run ./fedora_setup.sh build and then ./fedora_setup.sh install work fine and you’re done. However, if you run into the Unable to find 'openssl/opensslconf-i686.h' error as shown below, then you have 32-bit operating system running on 64-bit hardware.

# don't forget to give yourself permission to execute the script
$ chmod u+x fedora_setup.sh
$ ./fedora_setup.sh build
running build
running build_py
running build_ext
building 'M2Crypto.__m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
swig -python -I/usr/include/python2.6 -I/usr/include -includeall -o SWIG/_m2crypto_wrap.c SWIG/_m2crypto.i
SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf-i686.h'
SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf-i686.h'
error: command 'swig' failed with exit status 1

Taking a look at fedora_setup.sh, we see arch =´uname -m´ which yields i686 but you’re really running i386 operating system. The simplest thing to do here is to just create a symbolic link of the file openssl/opensslconf-i386.h to openssl/opensslconf-i686.h.

Finally, installing M2Crypto for 32-bit CentOS, RedHat and Fedora running on 64-bit harware:

# just to make sure our file name database is up-to-date
$ sudo updatedb

# locate opensslconf-* file
$ locate openssl|grep 'opensslconf-'
/usr/include/openssl/opensslconf-i386.h

# create a symbolic link
$ sudo ln -s /usr/include/openssl/opensslconf-i386.h /usr/include/openssl/opensslconf-i686.h

# just build & install and you're all set!
$ ./fedora_setup.sh build
$ ./fedora_setup.sh install