Logo Questions Linux Laravel Mysql Ubuntu Git Menu

ImportError: No module named _ctypes running Python Flask tutorial for Google App Engine on Windows

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)\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
like image 698
Bill Avatar asked Feb 05 '23 09:02


2 Answers

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

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

This sample shows how to use Flask with Google App Engine Standard.

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

pip install -t lib -r requirements.txt

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


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.

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

like image 92
snakecharmerb Avatar answered Feb 13 '23 05:02


For me, the workaround mentioned here Google's issue tracker worked

  • goto [sdk_home]\google\appengine\tools\devappserver2\python\sandbox.py
  • find the definition of _WHITE_LIST_C_MODULES = [xxx] add following two lines to the list:
    '_winreg', '_ctypes',
  • try your app again.

The issue was marked fixed on 7/7/2017.

like image 34
tdc Avatar answered Feb 13 '23 05:02