title: ImportError: No module named _ctypes. Google app engine with bokeh plot
body: <ul>
  <li>Python 2.7.13</li>
  <li>Windows 10 64 bit</li>
  </ul>
  
  <p>I've been working through this <a href="https://www.udacity.com/course/web-development--cs253" rel="nofollow noreferrer">Udacity web dev course</a> and wanted to try embedding a simple bokeh plot into a web page using <a href="http://docs.bokeh.org/en/latest/docs/user_guide/embed.html#components" rel="nofollow noreferrer">this example</a>. Running <code>dev_appserver.py</code> gives the error: <code>ImportError: No module named _ctypes</code></p>
  
  <p>I have:</p>
  
  <ul>
  <li>Installed Bokeh and Numpy via pip</li>
  <li>Included Numpy in app.yaml</li>
  </ul>
  
  <p><a href="https://stackoverflow.com/questions/41525223/importerror-no-module-named-ctypes-running-python-flask-tutorial-for-google-ap">This answer</a> states Google App Engine doesn't allow importing ctypes. However I'm unsure how to confirm if this is the case with Bokeh. Is this error caused by Bokeh importing ctypes? If so is there a work around?</p>
  
  <pre><code>ERROR    2017-01-21 19:14:53,799 wsgi.py:263]
  Traceback (most recent call last):
    File "C:\Users\AppData\Local\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:\Users\AppData\Local\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:\Users\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform
  \google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
      obj = __import__(path[0])
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\main.py", line 2, in &lt;module&gt;
      from bokeh.plotting import figure
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\lib\bokeh\plotting\__init__.py", line 2, in &lt;module
  &gt;
      from ..document import Document; Document
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\lib\bokeh\document.py", line 45, in &lt;module&gt;
      from .core.json_encoder import serialize_json
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\lib\bokeh\core\json_encoder.py", line 43, in &lt;modul
  e&gt;
      import numpy as np
    File "C:\Users\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform
  \google_appengine\google\appengine\tools\devappserver2\python\sandbox.py", line
  706, in load_module
      module = self._find_and_load_module(fullname, fullname, [module_path])
    File "C:\Users\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform
  \google_appengine\google\appengine\tools\devappserver2\python\sandbox.py", line
  447, in _find_and_load_module
      return imp.load_module(fullname, source_file, path_name, description)
    File "D:\Python27\lib\numpy\__init__.py", line 142, in &lt;module&gt;
      from . import add_newdocs
  INFO     2017-01-21 19:14:53,859 module.py:806] default: "GET / HTTP/1.1" 500 -
    File "D:\Python27\lib\numpy\add_newdocs.py", line 13, in &lt;module&gt;
      from numpy.lib import add_newdoc
    File "D:\Python27\lib\numpy\lib\__init__.py", line 8, in &lt;module&gt;
      from .type_check import *
    File "D:\Python27\lib\numpy\lib\type_check.py", line 11, in &lt;module&gt;
      import numpy.core.numeric as _nx
    File "D:\Python27\lib\numpy\core\__init__.py", line 33, in &lt;module&gt;
      from . import _internal  # for freeze programs
    File "D:\Python27\lib\numpy\core\_internal.py", line 14, in &lt;module&gt;
      import ctypes
    File "D:\Python27\lib\ctypes\__init__.py", line 7, in &lt;module&gt;
      from _ctypes import Union, Structure, Array
    File "C:\Users\AppData\Local\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
  </code></pre>
  
  <p>app.yaml:</p>
  
  <pre><code>runtime: python27
  api_version: 1
  threadsafe: true
  
  handlers:
  - url: /.*
    script: main.app
  
  libraries:
  - name: jinja2
    version: latest
  - name: numpy
    version: latest
  </code></pre>
  
  <p>main.py</p>
  
  <pre><code>import os, webapp2, jinja2
  from bokeh.plotting import figure
  from bokeh.embed import components
  
  plot = figure()
  plot.circle([1,2], [3,4])
  script, div = components(plot)
  
  template_dir = os.path.join(os.path.dirname(__file__), 'templates')
  jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
                                  autoescape = True)
  
  class Handler(webapp2.RequestHandler):
      def write(self, *a, **kw):
          self.response.write(*a, **kw)
  
      def render_str(self, template, **kw):
          t = jinja_env.get_template(template)
          return t.render(kw)
  
      def render(self, template, **kw):
          self.write(self.render_str(template, **kw))
  
  class MainPage(Handler):
      def get(self):
          self.render("chart.html", script = script, div = div)
  
  app = webapp2.WSGIApplication([
      ('/', MainPage),
  ], debug=True)
  </code></pre>
  
  <p>chart.html</p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block content %}
  
  &lt;!-- Load BokehJS --&gt;
  &lt;link
      href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.0.min.css"
      rel="stylesheet" type="text/css"&gt;
  &lt;link
      href="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.0.min.css"
      rel="stylesheet" type="text/css"&gt;
  
  &lt;script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.0.min.js"&gt;&lt;/script&gt;
  &lt;script src="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.0.min.js"&gt;&lt;/script&gt;
  
  {{ script }}
  {{ div }}
  
  {% endblock %}
  </code></pre>
  
  <p>base.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Udacity Templates!&lt;/title&gt;
  &lt;/head&gt;
  &lt;body style="margin: 0"&gt;
      &lt;h1 style="background-color: #ddd; color: #888; margin: 0; height: 50px"&gt;Udacity Templates&lt;/h1&gt;
      {% block content %}
      {% endblock %}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>gcloud version</p>
  
  <ul>
  <li>Google Cloud SDK 139.0.1 </li>
  <li>app-engine-python 1.9.49 </li>
  <li>bq 2.0.24 </li>
  <li>bq-win 2.0.24 </li>
  <li>bundled-python 2.7.10 </li>
  <li>core 2017.01.12 </li>
  <li>core-win 2016.11.07 </li>
  <li>gcloud    </li>
  <li>gsutil 4.22 </li>
  <li>gsutil-win 4.20 </li>
  <li>powershell 1.0.0.1         </li>
  <li>windows-ssh-tools 2016.05.13</li>
  </ul>
  
  <p><strong>UPDATE 1:</strong>
  I have uninstalled numpy 1.12.0 and installed numpy 1.6.1. I now get this error: </p>
  
  <pre><code>NP_MS_DELTA = np.timedelta64(1, 'ms')
  TypeError: function takes at most 1 argument (2 given)
  </code></pre>
  
  <p><a href="https://docs.scipy.org/doc/numpy/reference/arrays.datetime.html" rel="nofollow noreferrer">This</a> states numpy 1.6.1 can't specify unit in scalar constructor. Does this mean Bokeh relies on numpy>1.6.1?</p>
  
  <pre><code>ERROR    2017-01-22 10:37:45,980 wsgi.py:263]
  Traceback (most recent call last):
    File "C:\Users\AppData\Local\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:\Users\AppData\Local\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:\Users\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform
  \google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
      obj = __import__(path[0])
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\main.py", line 2, in &lt;module&gt;
      from bokeh.plotting import figure
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\lib\bokeh\plotting\__init__.py", line 2, in &lt;module
  &gt;
      from ..document import Document; Document
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\lib\bokeh\document.py", line 45, in &lt;module&gt;
      from .core.json_encoder import serialize_json
    File "C:\Users\Google Drive\Udacity web development 2017\udacit
  y-cs253\bokeh\1_docs_example\lib\bokeh\core\json_encoder.py", line 53, in &lt;modul
  e&gt;
      NP_MS_DELTA = np.timedelta64(1, 'ms')
  TypeError: function takes at most 1 argument (2 given)
  INFO     2017-01-22 10:37:46,170 module.py:806] default: "GET / HTTP/1.1" 500 -
  </code></pre>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>This reminds me of when I pip installed Bokeh. When downloading it's dependency numpy it seemed to rely on numpy>=1.7.1:</p>
  
  <pre><code>Collecting numpy&gt;=1.7.1 (from Bokeh)
  </code></pre>