I have spent a lot of time searching the Internet to make PyCrypto work in GAE development environment on Mac. For some reason AppEngine development server doesn’t like the latest PyCrypto v2.6 library. I have read a lot of posts about it but non of them helped. Errors I was getting were:
from Crypto.Cipher import _AES ImportError: cannot import name _AES
import Crypto ImportError: No module named Crypto
from Crypto.Cipher import AES # @UnresolvedImport ImportError: No module named Crypto.Cipher
from Crypto.Cipher import blockalgo ImportError: cannot import name blockalgo
and so on…
The solution was really simple. I downloaded PyCrypto version 2.4.1 form https://github.com/dlitz/pycrypto/tags and installed it. This solved the problem right away.
Make sure you have the right version of Python.
Open the terminal and type:
$ python -V Python 2.5.6
As you can see I have Python 2.5 installed. This is one of the recommended versions to do development on Google AppEngine. If you don’t have Python installed or it’s in the wrong version you can always use MacPorts to install the one you want. If you are new to MacPorts check out my video tutorial and blog post to learn how to install and use ports.
Now check where
site-packages directory is:
$ python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages</pre>
You should check if you already have PyCrypto installed in there. If you do, remove it either by hand or if you installed it through MacPorts use the command:
$ sudo port uninstall py25-crypto
Download and install PyCrypto 2.4.1
Go to https://github.com/dlitz/pycrypto/tags and download the zip or tar.gz file for version 2.4.1. When it’s done go to your terminal and do:
$ cd ~/Downloads $ tar xzf dlitz-pycrypto-v2.4.1-0-g62247ca.tar.gz $ cd dlitz-pycrypto-724dc72 $ python ./setup.py build
If you get an error here that means you do not have all the development libraries / compilers installed on your Mac. You will have to install it before you can go further. Assuming everything is all right you can install the PyCrypto using command:
$ sudo python ./setup.py install
That’s all I had to do to make it work. Hope that helps somebody.