Matplotlib与Google应用引擎本地开发

2024-09-28 05:28:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在我的googleappengine项目中使用matplotlib。我遵循了官方文件中描述的步骤。我所做的:

1)在我的应用程序根目录中创建了一个名为lib的目录。在

2)创建了一个appengine文件_配置.py在我的应用程序根目录中添加了以下行:

from google.appengine.ext import vendor
vendor.add('lib')

3)由于文档上说matplotlib的工作版本只有1.2.0,所以我在终端中执行了以下命令:

^{pr2}$

文档中还有第0步,即

Use pip to install the library and the vendor module to enable importing packages from the third-party library directory.

但我不明白这到底意味着什么。如果这是必要的,请向我解释一下这是什么意思。我在stackoverflow上找到了this答案,似乎与我所做的没有什么不同。在

我还补充道

libraries:
- name: matplotlib
  version: "1.2.0"

到应用程序yaml. 在

在所有这些步骤之后,我添加了一行

import matplotlib

到主.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

我做错什么了?在


Tags: infrompyimportnumpyhomematplotliblib
2条回答

对这个问题的一些研究发现了这个(旧)方法:

http://code.activestate.com/recipes/578393-gae-matplotlib-demo/

一定要阅读评论。在

不管我怎么努力,我都没能成功。可能是这种方法不再适用于当前版本的appengine沙盒,或者我只是不能正确地遵循配方中的所有步骤。在

也许更好的读物是mattgiuca(一位google工程师,他将matplotlib移植到GAE production env中)的评论和他在github中的请求。在

https://github.com/matplotlib/matplotlib/issues/1823/

他在2013年4月17日的评论中给出了一个匹配dev_appserver(版本1.77)以在本地使用matplotlib的方法。在

也许这有助于解决这个问题。在

matplotlibGoogle-provided 3rd party libs之一,因此您应该只遵循Requesting a library指令和 不是那些Installing a library的。在

遗憾的是,它们现在都在同一个文档页上,称为Using Built-in Libraries in Python 2.7-这对于那些不知道的人来说非常混乱,因为vendoring技术应该用于不是GAE内置/提供的库。归档Issue 13202。在

注意:注意Using libraries with the local development server部分,它适用于matplotlib。您可能需要在您的系统上安装一些包,但是不是在应用程序本身中(这可能会对您在GAE上的部署产生负面影响)-它们需要由开发服务器访问,而不是直接由应用程序访问。在

{我注意到了这一页)

它提到:

Note: The experimental release of matplotlib is not supported on the development server. You can still add matplotlib to the libraries list, but it will raise an ImportError exception when imported.

相关问题 更多 >

    热门问题