我想在我的Google App Engine項目中使用matplotlib。我遵循了在官方文檔中描述here的步驟。我做了什麼:帶Google App Engine本地開發服務器的Matplotlib
1)在我的應用程序根目錄下創建一個名爲lib的目錄。
2)創建的文件appengine_config.py在我的應用程序的根目錄,並添加有這些行:
from google.appengine.ext import vendor
vendor.add('lib')
3)由於文檔說,這matplotlib工作的唯一版本是1.2.0,我執行在終端下面的命令:
pip install -t lib matplotlib==1.2.0
有在文檔也步驟0,這表示
使用pip安裝庫和供應商模塊以啓用從第三方庫目錄導入包。
但我不明白它的實際含義。如果這是必不可少的,請向我解釋這是什麼意思。我在stackoverflow上找到了this的答案,看起來和我所做的沒有什麼不同。
另外,我補充
libraries:
- name: matplotlib
version: "1.2.0"
到app.yaml中。
因此,所有這些步驟後,我行添加
import matplotlib
在main.py和啓動本地服務器
python ~/path/google_appengine/dev_appserver.py app.yaml
但是,當我嘗試訪問http://localhost:8080/,將引發錯誤:
raise ImportError('No module named %s' % fullname)
ImportError: No module named _ctypes
如果需要,整個輸出如下所示:
ERROR 2016-08-11 16:26:51,621 wsgi.py:263]
Traceback (most recent call last):
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/home/magnitofon/realec-inspector/main.py", line 20, in <module>
import matplotlib
File "/home/magnitofon/realec-inspector/lib/matplotlib/__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/home/magnitofon/realec-inspector/lib/matplotlib/rcsetup.py", line 20, in <module>
from matplotlib.colors import is_color_like
File "/home/magnitofon/realec-inspector/lib/matplotlib/colors.py", line 52, in <module>
import numpy as np
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 705, in load_module
module = self._find_and_load_module(fullname, fullname, [module_path])
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 446, in _find_and_load_module
return imp.load_module(fullname, source_file, path_name, description)
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 22, in <module>
from . import _internal # for freeze programs
File "/usr/local/lib/python2.7/dist-packages/numpy/core/_internal.py", line 14, in <module>
import ctypes
File "/usr/lib/python2.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
File "/home/magnitofon/Загрузки/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 963, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named _ctypes
我在做什麼錯?
所以,我不能在本地服務器上使用matplotlib,因爲總會有一個ImportError。雖然,我仍然可以在我的應用程序代碼中使用matplotlib,然後將應用程序部署到Google App Enging,並且它將在那裏工作? 我理解正確嗎? –
這也是我對文檔的理解。 –
謝謝你的回答。 我使用了[this](http://gae-matplotlib-demo.appspot.com/)示例,matplotlib在部署後成功運行。儘管它不是一個可以在本地運行的可信的人,但我仍然很高興它能夠運行。 –