Jon Atkinson

I'm a technologist, with a long and varied history in high-end technical delivery and infrastructure management. I'm particularly interested in managing software teams, rapid application development, and scalability challenges.

Installing M2Crypto on OSX

9th October 2008

I really like M2Crypto, but it is difficult to install on OSX without a few annoying prerequisites. Assuming you are running Leopard (or, I guess, newer), this is what you need to do:

First, you need to install the XCode Developer Tools. You probably have these installed already, but if not, they're on your OS install discs, or you can download them from Apple. Once they're installed, you should have a working C compiler. Test with:

$ gcc
i686-apple-darwin9-gcc-4.0.1: no input files

Now, you need to install the OpenSSL headers. Grab the latest OpenSSL package from here. Now, unpack and build it. You might want to put the kettle on, this takes a little while.

$ tar xzf openssl-x.x.x.tar.gz
$ cd openssl-x-x-x
$ ./config --prefix=/usr/local
$ make && make test
$ sudo make install

Next, download SWIG. Again, this needs unpacking and building:

$ tar xzf swig-x.x.x.tar.gz
$ cd swig-x.x.x
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

Finally, you need to download and install M2Crypto. Grab the source, and install it as follows:

$ tar xzf M2Crypto-x.x
$ cd M2Crypto-x.x
$ python setup.py build build_ext --openssl=/usr/local
$ sudo python setup.py install build_ext --openssl=/usr/local

Then to test your installation, simply do the following:

$ python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import M2Crypto