Thursday, July 26, 2012

Building PyCrypto on Amazon EC2

I setup a new AMI Linux instance in the EC2 cloud today primarily for playing around with Python and possibly building some small web apps. Shortly after firing up the instance, I tried to build and install PyCrypto and ran into some problems. It was a bit of an adventure. Here's how I got it working:Step 1 - Install gcc/make

There are two problems you'll run into if you try to build PyCrypto at this point: errors from missing header files and, once you resolve those, runtime errors complaining about an undefined symbol for rpl_malloc. Let's fix that.

The problem is that when you try to build PyCrypto, autotools thinks that we're using rpl_malloc instead of malloc. I'm not sure how to fix this problem the right way, but this hack will get rid of the check and just have it use malloc. If someone knows the right way to fix this, please say something in the comments and I'll update this post.

Step 7 - Build PyCrypto

$ python setup.py build
$ sudo python.setup.py install

Step 8 - Test PyCrypto

$ python
>>> from Crypto.Cipher import AES

If this works, you should be good to go.

If it fails, you did something wrong. You can either rm -r pycrypto-2.6 and re-extract the archive or just rm -r the build folder then grep for anything that says "rpl_malloc" and comment it out. Also edit config.status and change 'D["HAVE_MALLOC"]=" 0"' to say '=" 1"'. This is what I did the first time, but when I decided to write this up I started over to try to get it right from the start.

Today, I had to rebuild PyCrypto from scratch into a brand new EC2 - (config: Amazon Linux AMI 2013.09.2 - ami-ccf297fc (64-bit) / ami-def297ee (32-bit)) with nothing in it -- fresh install. I've done it about a year ago, however lost my notes : ( .

So thank you very much for providing the steps above! Very handy.. However, on a truly fresh EC2 instance per above, here are some additional notes I had to do to do a full end2end clean/error free install of PyCrypto: