App Engine module import issue
<p>I am writing unit tests for a Flask based application running on App Engine. </p>

<p>As per the <a href="https://cloud.google.com/appengine/docs/python/tools/localunittesting" rel="nofollow">documentation</a>, I have included the following lines</p>

<pre><code>import sys

sys.path.insert(1, '/Users/vinay/tools/google_appengine')
sys.path.insert(1, '/Users/vinay/tools/google_appengine/lib/yaml/lib')
sys.path.insert(1, '/Users/vinay/App-Engine/zion-alpha/lib')
</code></pre>

<p>Here is the full test file. </p>

<pre><code>import sys

sys.path.insert(1, '/Users/vinay/tools/google_appengine')
sys.path.insert(1, '/Users/vinay/tools/google_appengine/lib/yaml/lib')
sys.path.insert(1, '/Users/vinay/App-Engine/zion-alpha/lib')

from pprint import pprint
pprint(sys.path)

from google.appengine.ext import ndb
from webtest import TestApp
from app import create_app
from Tests.base_test import TestBase

app = TestApp(create_app())


class AppTest(TestBase):
    def test_index(self):
        response = app.get('/')
        self.assertEqual(response.content_type, 'text/plain')
        self.assertEqual('Hello World', response.body)
</code></pre>

<p>When I run this script I get the following error. </p>

<pre><code>/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py /Users/vinay/App-Engine/zion-alpha/Tests/handler_tests.py true
Testing started at 10:31 AM ...
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py", line 121, in &lt;module&gt;
    modules = [loadSource(a[0])]
  File "/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py", line 43, in loadSource
    module = imp.load_source(moduleName, fileName)
  File "/Users/vinay/App-Engine/zion-alpha/Tests/handler_tests.py", line 10, in &lt;module&gt;
    from google.appengine.ext import ndb
ImportError: No module named appengine.ext
['/Users/vinay/App-Engine/zion-alpha/Tests',
 '/Users/vinay/App-Engine/zion-alpha/lib',
 '/Users/vinay/tools/google_appengine/lib/yaml/lib',
 '/Users/vinay/tools/google_appengine',
 '/Library/Python/2.7/site-packages/python_gflags-2.0-py2.7.egg',
 '/Library/Python/2.7/site-packages/xunitparser-1.3.3-py2.7.egg',
 '/Library/Python/2.7/site-packages/setuptools-20.6.7-py2.7.egg',
 '/Library/Python/2.7/site-packages',
 '/Users/vinay/tools/google_appengine/lib/apiclient',
 '/Users/vinay/tools/google_appengine/lib/markupsafe-0.15',
 '/Users/vinay/tools/google_appengine/lib/concurrent',
 '/Users/vinay/tools/google_appengine/lib/distutils',
 '/Users/vinay/tools/google_appengine/lib/httplib2',
 '/Users/vinay/tools/google_appengine/lib/fancy_urllib',
 '/Users/vinay/tools/google_appengine/lib/oauth2client',
 '/Users/vinay/tools/google_appengine/lib/cacerts',
 '/Users/vinay/tools/google_appengine/lib/requests',
 '/Users/vinay/tools/google_appengine/lib/cherrypy',
 '/Users/vinay/tools/google_appengine/lib/ipaddr',
 '/Users/vinay/tools/google_appengine/lib/prettytable',
 '/Users/vinay/tools/google_appengine/lib/grizzled',
 '/Users/vinay/App-Engine/zion-alpha/lib',
 '/Users/vinay/tools/google_appengine/lib/rsa',
 '/Users/vinay/tools/google_appengine/lib/oauth2',
 '/Users/vinay/tools/google_appengine/lib/pyasn1',
 '/Users/vinay/tools/google_appengine/lib/sqlcmd',
 '/Users/vinay/tools/google_appengine/lib/webob-1.2.3',
 '/Users/vinay/tools/google_appengine/lib/antlr3',
 '/Users/vinay/tools/google_appengine/lib/jinja2-2.6',
 '/Users/vinay/tools/google_appengine/lib/endpoints-1.0',
 '/Users/vinay/tools/google_appengine/lib/graphy',
 '/Users/vinay/tools/google_appengine/lib/websocket',
 '/Users/vinay/tools/google_appengine/lib/google-api-python-client',
 '/Users/vinay/tools/google_appengine/lib/setuptools-0.6c11',
 '/Users/vinay/tools/google_appengine/lib/yaml-3.10',
 '/Users/vinay/tools/google_appengine/lib/docker',
 '/Users/vinay/tools/google_appengine',
 '/Users/vinay/tools/google_appengine/lib/mox',
 '/Users/vinay/tools/google_appengine/lib/django-1.9',
 '/Users/vinay/tools/google_appengine/lib/six',
 '/Users/vinay/tools/google_appengine/lib/webapp2-2.5.2',
 '/Users/vinay/tools/google_appengine/lib/deprecated_enum',
 '/Users/vinay/tools/google_appengine/lib/portpicker',
 '/Users/vinay/tools/google_appengine/lib/argparse',
 '/Users/vinay/tools/google_appengine/lib/uritemplate',
 '/Users/vinay/tools/google_appengine/lib/protorpc-1.0',
 '/Users/vinay/tools/google_appengine/lib/PyAMF-0.7.2',
 '/Users/vinay/tools/google_appengine/lib/simplejson',
 '/Users/vinay/App-Engine/zion-alpha',
 '/Users/vinay/tools/google_appengine/lib/PyAMF-0.6.1',
 '/Users/vinay/tools/google_appengine/lib/pyasn1_modules',
 '/Users/vinay/tools/google_appengine/lib/python-gflags',
 '/Applications/PyCharm.app/Contents/helpers/pycharm',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/var/root/Library/Python/2.7/lib/python/site-packages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']

Process finished with exit code 1
</code></pre>

<p>The package is located at the right location. </p>

<pre><code>bash-3.2$ ls
google_appengine        google_appengine_1.9.40.zip
bash-3.2$ pwd
/Users/vinay/tools
bash-3.2$ 
</code></pre>

<p>Looks like you don't have the <code>google_appengine</code> package where you think you do.  You will not see an error if you try to add a nonexistent path to your sys path.  Add this between lines 5 and 7 to check your path:</p>

<pre><code>from pprint import pprint 
pprint(sys.path)
</code></pre>

<p>Check for more than 1 appengine packs in paths.  Navigate to each to make sure it's really there.</p>

python python-2.7 google-app-engine