Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use numpy in google app engine (Python)

numpy is supported as a library in google app engine according to the official documentation here. I was not able to import it after a few trials, can anyone share the code to use it?

I believe it should be called in app.yaml with:

libraries:
- name: numpy
  version: "1.6.1"

And then be imported in the script somehow. I tried the obvious:

import numpy

but it gave me the following error:

ImportError: No module named numpy

Any simple code is appreciated, for example how do you do the "numpy.average" function in a google app engine script?

>>> data = range(1,5)
>>> data
[1, 2, 3, 4]
>>> np.average(data)
2.5
like image 803
Saint Avatar asked Jul 10 '12 17:07

Saint


1 Answers

If you want it to work locally you have to download and install it locally (I got mine from here http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy)

Besides that you have to make sure you are running python27, and that you're importing it in the app.yaml file, e.g.:

application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /.*
  script: helloworld.py

libraries:
- name: numpy
  version: "1.6.1"
like image 163
Uri Avatar answered Nov 12 '22 02:11

Uri