在Google App Engine中使用Matplotlib
我在把matplotlib导入到谷歌应用引擎时遇到了麻烦。我在网上查了很多资料,找到了几种解决办法,但都不适合我。在我的app.yaml文件里,我有
libraries:
- name: matplotlib
version: latest
- name: numpy
version: latest
在我的Python文件中,我会导入numpy,我可以有
numpy.arange(10)
问题是当我尝试导入matplotlib时
import matplotlib as plt
我在访问页面时遇到了这个错误
The website encountered an error while retrieving http://localhost:8080/.
It may be down for maintenance or configured incorrectly.
我把matplotlib的导入去掉,刷新一下,所有东西又都能正常工作了。我看到一些应用引擎网页使用了matplotlib,比如http://gae-matplotlib-demo.appspot.com,它们也导入了matplotlib,所以我知道这是可能的。
我该如何在谷歌应用引擎中使用matplotlib呢?
1 个回答
5
很遗憾,Matplotlib 目前在 GAE 开发应用服务器上无法使用,具体情况可以在 Matplotlib 的说明中找到。这在开发阶段并不是一个理想的选择,但如果你把它部署到生产服务器上,使用 appcfg 的话,它是可以正常工作的。我们会在开发服务器支持 Matplotlib 后更新这个页面。
正如 @mjibson 提到的,Dima Tisnek 找到了一个方法,可以让 Matplotlib 在开发应用服务器上运行,但这个方法需要一些技巧,我们并不正式支持这种做法。(顺便说一下,我用这个方法成功让它运行了。)
Matt Giuca
谷歌