title: Google App Engine: ImportError: No module named appengine.ext
body: <p>I am trying to write a test for my GAE programme which uses the datastore.
  Following <a href="https://cloud.google.com/appengine/docs/python/tools/localunittesting" rel="nofollow">Google's Documentation</a>, I see that I should be adding the path to my SDK into my PYTHONPATH. 
  I did this using:</p>
  
  <pre><code>import sys
  sys.path.remove('/usr/local/lib/python2.7/dist-packages')    # Has a 'google' module, which I want to be sure isn't interfering.
  sys.path.insert(1,'/home/olly/google-cloud-sdk/platform/google_appengine')
  sys.path.insert(1, '/home/olly/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
  </code></pre>
  
  <p>Then when the file is run:</p>
  
  <pre><code>Traceback (most recent call last):
   File "myapp_tests.py", line 20, in &lt;module&gt;
      from google.appengine.ext import ndb
  ImportError: No module named appengine.ext
  </code></pre>
  
  <p>I have installed the SDK in the location above, and looking in <code>/home/olly/google-cloud-sdk/platform/google_appengine/</code> I found the <code>google</code> folder, which has an <code>__init__.py</code> in it, along with <code>appengine</code>. Basically, the folder structure looks good to me, with them all being named correctly and having <code>__init__.py</code> files.</p>
  
  <p>In an interactive console, after running the commands above, I found that I could run:</p>
  
  <pre><code>import google
  </code></pre>
  
  <p>no problem, but when I tried </p>
  
  <pre><code>import google.appengine
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  ImportError: No module named appengine
  </code></pre>
  
  <p>It was my understanding that having the <code>__init__.py()</code> files in the directories meant that they could be imported as above.
  I also did a <code>sudo find / --name "google"</code>, and the only thing that showed up that is also in my PYTHONPATH was the <code>/usr/local/lib/python2.7/dist-packages</code>, which I explicitly removed, and also inserted the rest of my paths in front of anyway.</p>
  
  <p>I tried using GAE's own method of:</p>
  
  <pre><code>import dev_appserver
  dev_appserver.fix_sys_path()
  </code></pre>
  
  <p>which added a whole lot of paths to sys.path, but still didn't help me make it work.</p>
  
  <p>I also found that when I add <code>'/home/olly/Servers/google_appengine/google'</code> to my paths, I can run:</p>
  
  <pre><code>import appengine.ext
  </code></pre>
  
  <p>but running:</p>
  
  <pre><code>from appengine.ext import ndb
  </code></pre>
  
  <p>causes: </p>
  
  <pre><code>Traceback (most recent call last):
    File "booking_function_tests.py", line 16, in &lt;module&gt;
       from appengine.ext import ndb
    File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/__init__.py", line 7, in &lt;module&gt;
       from tasklets import *
    File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/tasklets.py", line 69, in &lt;module&gt;
       from .google_imports import apiproxy_stub_map
    File "/home/olly/Servers/google_appengine/google/appengine/ext/ndb/google_imports.py"    , line 11, in &lt;module&gt;
       from google3.storage.onestore.v3 import entity_pb
  ImportError: No module named google3.storage.onestore.v3
  </code></pre>
  
  <p>Am I missing something really obvious? How should I go about importing ndb?</p>
  
  <p>EDIT:
  I'm running the latest SDK (1.9.34), but I have the following code in my google_imports.py:</p>
  
  <pre><code>try:
    from google.appengine.datastore import entity_pb
    normal_environment = True
  except ImportError:
    try:
      from google3.storage.onestore.v3 import entity_pb
      normal_environment = False
    except ImportError:
      # If we are running locally but outside the context of App Engine.
      try:
        set_appengine_imports()
        from google.appengine.datastore import entity_pb
        normal_environment = True
      except ImportError:
        raise ImportError('Unable to find the App Engine SDK. '
                          'Did you remember to set the "GAE" environment '
                          'variable to be the path to the App Engine SDK?')
  </code></pre>
  
  <p>Also, <code>google.__path__</code> gives me the <code>'/usr/local/lib/python2.7/dist-packages'</code> path which I thought I removed earlier. Here is an excerpt of how I'm removing it:</p>
  
  <pre><code>import sys
  sys.path.insert(1, '/home/olly/Servers/google_appengine')
  sys.path.insert(1, '/home/olly/Servers/google_appengine/lib/yaml/lib')
  sys.path.remove('/usr/local/lib/python2.7/dist-packages')
  
  import google
  print google.__path__
  print sys.path
  
  
  ['/usr/local/lib/python2.7/dist-packages/google']
  ['/home/olly/Servers/google_appengine/myapp', '/home/olly/Servers/google_appengine/lib/yaml/lib', '/home/olly/Servers/google_appengine/google', '/home/olly/Servers/google_appengine', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
  </code></pre>
  
  <p>So my sys.path is updated, but <code>import google</code> seems to still be importing from the no-longer-there path, which would be the crux of my problem I guess. Do I need to reload the path or something?</p>