ImportError: No module named _ctypes. Google app engine with bokeh plot

I managed to get the dev server running using 2 hacks

ImportError: No module named _ctypes

This is actually caused by flask New Flask uses library named click which uses ctypes Gae doesn't allow ctypes Solution: Install and older version of click with

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

This fixes ctypes but causes another error

ImportError: No module named msvcrt

This can be easily fixed by adding this lines to appengine_config.py (located in the same folder as app.yaml )

import os, sys

on_appengine = os.environ.get('SERVER_SOFTWARE','').startswith('Development')
if on_appengine and os.name == 'nt':
    sys.platform = "Not Windows"

After this dev servers starts and works


work around issued from google here:

https://issuetracker.google.com/issues/38290292

  • goto <sdk_root>\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.

worked for me.


Edit: Please see the answer below for a new workaround from Google.


I can state categorically that Bokeh itself does not use ctypes directly, anywhere in the library. But it does use NumPy, and it seems that at least some versions of NumPy do use ctypes? This link:

http://kawahara.ca/using-numpy-on-google-app-engine-with-the-anaconda-python-distribution/

seems to suggest that only version 1.6 of NumPy is supported on GAE. I might assume this is either because that version does not use ctypes, or because Google has specifically whitelisted that version as acceptable somehow.

So the suggestion would be specifically install NumPy 1.6, and not the latest version (either using pip or conda or whatever).