Saint
Saint

Reputation: 486

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

Upvotes: 13

Views: 6126

Answers (2)

Uri
Uri

Reputation: 26966

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"

Upvotes: 12

Bovard
Bovard

Reputation: 1195

You can check out the code for the Predator app demoed in the Getting the Most Out of Python 2.7 on App Engine by Brian Quinlan. He walks you through it starting at 11:00

Upvotes: 0

Related Questions