本文介绍了导入错误:没有名为 _ctypes 的模块在 Windows 上运行适用于 Google App Engine 的 Python Flask 教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm just trying to run the simple hello world app on their tutorials page. I used to use Google App Engine frequently, but now I can't seem to get it going at all. I'm on win 10 x64. Downloaded latest google cloud sdk, and python version 2.7.13

> ERROR    2017-01-07 15:25:21,219 wsgi.py:263] Traceback (most recent
> call last):   File "C:Program Files (x86)GoogleCloud
> SDKgoogle-cloud-sdkplatformgoogle_appenginegoogleappengine
untimewsgi.py",
> line 240, in Handle
>     handler = _config_handle.add_wsgi_middleware(self._LoadHandler())   File "C:Program Files (x86)GoogleCloud
> SDKgoogle-cloud-sdkplatformgoogle_appenginegoogleappengine
untimewsgi.py",
> line 299, in _LoadHandler
>     handler, path, err = LoadObject(self._handler)   File "C:Program Files (x86)GoogleCloud
> SDKgoogle-cloud-sdkplatformgoogle_appenginegoogleappengine
untimewsgi.py",
> line 85, in LoadObject
>     obj = __import__(path[0])   File "C:....python-docs-samplesappenginestandardflaskhello_worldmain.py",
> line 18, in <module>
>     from flask import Flask   File "C:....python-docs-samplesappenginestandardflaskhello_worldlibflask\__init__.py",
> line 21, in <module>
>     from .app import Flask, Request, Response   File "C:....python-docs-samplesappenginestandardflaskhello_worldlibflaskapp.py",
> line 27, in <module>
>     from . import json, cli   File "C:....python-docs-samplesappenginestandardflaskhello_worldlibflaskcli.py",
> line 17, in <module>
>     import click   File "C:....python-docs-samplesappenginestandardflaskhello_worldlibclick\__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-samplesappenginestandardflaskhello_worldlibclickcore.py", line 8, in <module>
>     from .types import convert_type, IntRange, BOOL   File "C:....python-docs-samplesappenginestandardflaskhello_worldlibclick	ypes.py",
> line 4, in <module>
>     from ._compat import open_stream, text_type, filename_to_ui,    File
> "C:....python-docs-samplesappenginestandardflaskhello_worldlibclick\_compat.py",
> line 536, in <module>
>     from ._winconsole import _get_windows_console_stream   File "C:....python-docs-samplesappenginestandardflaskhello_worldlibclick\_winconsole.py",
> line 16, in <module>
>     import ctypes   File "C:Python27libctypes\__init__.py", line 7, in <module>
>     from _ctypes import Union, Structure, Array   File "C:Program Files (x86)GoogleCloud
> SDKgoogle-cloud-sdkplatformgoogle_appenginegoogleappengine	oolsdevappserver2pythonsandbox.py",
> line 964, in load_module
>     raise ImportError('No module named %s' % fullname) 
ImportError: No module named _ctypes

推荐答案

Google 的示例 FlaskHello World"应用程序需要 Flask 0.11.1.

Google's sample Flask "Hello World" application requires Flask 0.11.1.

这个库不是由 Google 提供的,所以开发者需要通过 pip

This library is not vendored by Google, so developers are required to install it via pip

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

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

Before running or deploying this application, install the dependencies using pip:

pip install -t lib -r requirements.txt

Flask 的 setup.py 指示 pip 安装 click 库,版本晚于或等于2.0版本.

Flask's setup.py instructs pip to install the click library, at a release later than or equal to version 2.0.

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

在 2015 年 11 月 提交了更改click改进 Windows 控制台中对 unicode 的支持.此更改添加了 Appengine 正在阻塞的 ctypes 库的导入,因为 Appengine 沙箱不允许导入 ctypes.

In November 2015 a change was committed to click to improve support for unicode in the windows console. This change added the import of the ctypes library which Appengine is choking on, because the Appengine sandbox does not allow importing ctypes.

解决此问题的方法是使用早期版本 (5.1 看起来像最近的候选人):

The workaround for this is to overwrite the installed click with an earlier version (5.1 looks like the most recent candidate):

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

这篇关于导入错误:没有名为 _ctypes 的模块在 Windows 上运行适用于 Google App Engine 的 Python Flask 教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 23:16