Using numpy on google app engine with the anaconda python distribution

– you are using the Google App Engine (GAE) development server with Python
– you installed the Anaconda Python distribution
– you want to use the Numpy library with GAE

On Ubuntu and on Mac (but not Windows for some reason), you get this error when trying to deploy:
google app engine ImportError: No module named _ctypes

The tldr; solution
Create an Anaconda environment using numpy 1.6 and python 2.7:

conda create -n np16py27 anaconda numpy=1.6 python=2.7

Load this specific environment from the command line:

source activate np16py27

Run your GAE dev server: my_gae_project

That’s it! You can read more details below if you are interested.

The solution explained
If you Google this error message, you might come across this link, which essentially notes that only Numpy 1.6.1 is supported on GAE and that the Numpy version installed on your local machine has to also be Numpy 1.6.1.

You check your version Numpy on Python and find that you are running numpy 1.11.1, which is a newer version.

$ python
>>> import numpy
>>> numpy.__version__

So we need to use an earlier version of numpy in Python to work with GAE.

The first thing I tried was to follow this link and revert to a previous version of numpy in Anaconda by running from the command line,

conda install numpy=1.6.1

However, numpy 1.6.1 seems to be so old that it wasn’t found (I think). Trying other older packages gives problems with dependencies – so this approach seems like a nightmare.

Eventually, I found this nifty feature of Anaconda, where you can actually multiple versions of python and numpy without messing up other parts of your system.

Basically, you just run this command from the command line to create a new environment for python 2.7 with numpy 1.6.1 (this works on Ubuntu):

conda create -name np16py27 anaconda numpy=1.6.1 python=2.7

I tried this on a Mac and it turns out that numpy 1.6.1 was not found. So I instead installed numpy 1.6 and let Mac choose what version (turned out to be numpy 1.6.2). This seemed to work fine with GAE.

conda create -n np16py27 anaconda numpy=1.6 python=2.7

Then to use this specific environment, from the command line just type in:

source activate np16py27

This will load python 2.7 with numpy 1.6. You can then run your dev_appserver to test your GAE project using numpy. my_gae_project

And that’s it! You should be up and running now to take full advantage on Numpy on GAE!


January 2, 2017:
Thanks to Carlos for pointing out an error with the hyphen character “-” in the command: conda create -n np16py27 anaconda numpy=1.6 python=2.7
Updated this post to use the correct hyphen so you can copy and paste this command correctly.