ImportError:没有名为_ctypes的模块在Windows上运行Google App Engine的Python Flask教程

时间:2017-01-07 18:53:45

标签: google-app-engine

我只是想在他们的教程页面上运行简单的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

2 个答案:

答案 0 :(得分:5)

Google的样本Flask&#34; Hello World&#34;申请需要Flask 0.11.1

Google不会销售此库,因此开发人员需要通过pip

进行安装
  

此示例显示如何将Flask与Google App Engine Standard一起使用。

     

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

     

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

答案 1 :(得分:2)

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

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

该问题已在2017年7月7日修复。