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

Bil*_*ill 4 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
Run Code Online (Sandbox Code Playgroud)

sna*_*erb 5

Google的样本Flask"Hello World"应用程序需要Flask 0.11.1.

此库不是由Google销售的,因此开发人员需要通过它来安装它 pip

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

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

pip install -t lib -r requirements.txt

Flask setup.py 指示 pip安装点击库,版本高于或等于2.0版本.

    install_requires=[
        'Werkzeug>=0.7',
        'Jinja2>=2.4',
        'itsdangerous>=0.21',
        'click>=2.0',
],
Run Code Online (Sandbox Code Playgroud)

在2015年11月变更承诺,以click改善在Windows控制台的Unicode支持.此更改添加了ctypesAppengine正在阻塞的库的导入,因为Appengine沙箱不允许导入ctypes.

解决方法是click使用早期版本覆盖已安装的版本(5.1 看起来像最近的候选版本):

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