Installing M2Crypto in a Python virtualenv on Ubuntu 13.10 Saucy

There are two bugs that prevent the python M2Crypto 0.21.1 package from being pip installed from pypi in a virtualenv on Ubuntu 13.10.

  • First bug #696327. libssl-dev is now multiarch and M2Crypto can’t find the opensslconf.h header:

      SWIG/_evp.i:12: Error: Unable to find 'openssl/opensslconf.h'
      SWIG/_ec.i:7: Error: Unable to find 'openssl/opensslconf.h'
      error: command 'swig' failed with exit status 1
    
  • Second bug #637750. If you do get M2Crypto to build by adding /usr/include/x86_64-linux-gnu/ to include_dirs in ~/.pydistutils.cfg, SSLv2 has been disabled in openssl and M2Crypto fails to import:

      >>> import M2Crypto
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/home/ubuntu/ENV/local/lib/python2.7/site-packages/M2Crypto/__init__.py", line 22, in <module>
          import __m2crypto
      ImportError: /home/ubuntu/ENV/local/lib/python2.7/site-packages/M2Crypto/__m2crypto.so: undefined symbol: SSLv2_method
    

The Ubuntu python-m2crypto package has patches for both these, in m2crypto_0.21.1-3ubuntu3.debian.tar.gz available here.

These have been merged into the debian git repository, so the easiest route is to use pip’s git support and install directly from there. The patches require you to specify your architecture using an environment variable so the full command for 64 bit would be:

DEB_HOST_MULTIARCH=x86_64-linux-gnu pip install "git+git://anonscm.debian.org/collab-maint/m2crypto.git@debian/0.21.1-3#egg=M2Crypto"
Written on November 1, 2013