【问题标题】:ImportError: No module named _ctypes running Python Flask tutorial for Google App Engine on WindowsImportError: No module named _ctypes running Python Flask tutorial for Google App Engine on Windows
【发布时间】:2017-05-22 08:50:45
【问题描述】:

我只是想在他们的教程页面上运行简单的 hello world 应用程序。我以前经常使用 Google App Engine,但现在我似乎根本无法使用它。我正在赢得 10 x64。下载了最新的google cloud sdk,和python 2.7.13版

> ERROR    2017-01-07 15:25:21,219 wsgi.py:263] Traceback (most recent
> call last):   File "C:\Program Files (x86)\Google\Cloud
> SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py",
> line 240, in Handle
>     handler = _config_handle.add_wsgi_middleware(self._LoadHandler())   File "C:\Program Files (x86)\Google\Cloud
> SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py",
> line 299, in _LoadHandler
>     handler, path, err = LoadObject(self._handler)   File "C:\Program Files (x86)\Google\Cloud
> SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py",
> line 85, in LoadObject
>     obj = __import__(path[0])   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\main.py",
> line 18, in <module>
>     from flask import Flask   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\flask\__init__.py",
> line 21, in <module>
>     from .app import Flask, Request, Response   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\flask\app.py",
> line 27, in <module>
>     from . import json, cli   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\flask\cli.py",
> line 17, in <module>
>     import click   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\click\__init__.py",
> line 18, in <module> INFO     2017-01-07 10:25:21,229 module.py:806]
> default: "GET / HTTP/1.1" 500 -
>     from .core import Context, BaseCommand, Command, MultiCommand, Group, \   File
> "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\click\core.py", line 8, in <module>
>     from .types import convert_type, IntRange, BOOL   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\click\types.py",
> line 4, in <module>
>     from ._compat import open_stream, text_type, filename_to_ui, \   File
> "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\click\_compat.py",
> line 536, in <module>
>     from ._winconsole import _get_windows_console_stream   File "C:\....\python-docs-samples\appengine\standard\flask\hello_world\lib\click\_winconsole.py",
> line 16, in <module>
>     import ctypes   File "C:\Python27\lib\ctypes\__init__.py", line 7, in <module>
>     from _ctypes import Union, Structure, Array   File "C:\Program Files (x86)\Google\Cloud
> SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\sandbox.py",
> line 964, in load_module
>     raise ImportError('No module named %s' % fullname) 
ImportError: No module named _ctypes

【问题讨论】:

标签: google-app-engine


【解决方案1】:

Google 的示例 Flask “Hello World”应用程序需要 Flask 0.11.1

此库并非由 Google 提供,因此开发者需要通过 pip 安装它

此示例展示了如何将 Flask 与 Google App Engine Standard 结合使用。

在运行或部署此应用程序之前,安装依赖项 使用点子:

pip install -t lib -r requirements.txt

Flask 的 setup.py instructs pip 用于安装 click 库,在高于或等于 2.0 版的版本中。

    install_requires=[
        'Werkzeug>=0.7',
        'Jinja2>=2.4',
        'itsdangerous>=0.21',
        'click>=2.0',
],

2015 年 11 月 a change was committedclick 以改进 Windows 控制台中对 unicode 的支持。此更改添加了 Appengine 阻塞的 ctypes 库的导入,因为 Appengine 沙箱不允许导入 ctypes

解决方法是用早期版本 (5.1 looks like the most recent candidate) 覆盖已安装的 click

pip install --target lib --upgrade click==5.1

【讨论】:

    【解决方案2】:

    对我来说,这里提到的解决方法Google's issue tracker 有效

    • 转到 [sdk_home]\google\appengine\tools\devappserver2\python\sandbox.py
    • 找到_WHITE_LIST_C_MODULES = [xxx]的定义 将以下两行添加到列表中:
      '_winreg', '_ctypes',
    • 再次尝试您的应用。

    该问题已于 2017 年 7 月 7 日标记为已修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 2019-04-03
      • 1970-01-01
      • 2017-02-20
      • 2018-07-20
      • 2015-02-27
      相关资源
      最近更新 更多