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

2019-04-04 14:17发布

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

2条回答
霸刀☆藐视天下
2楼-- · 2019-04-04 14:55

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"
查看更多
可以哭但决不认输i
3楼-- · 2019-04-04 15:05

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

查看更多
登录 后发表回答