python with app engine error import ndb
Question: I have a problem with app engine, I use it with django. I read a lot of thinks
about the problem, but I never find a solution. I use Pycharm for the
development, I just use app engine in the models.py

For import ndb I make this :

    
    
    from google.appengine.ext import ndb
    

There is my problem: If I use "dev_appserver.py ." I don't have any problems
and the application work fine.

But when I use "python manage.py test mobile_backend/" I have an error.

> from google.appengine.ext import ndb  
>  ImportError: No module named appengine.ext

After some hours searching, the solution I have verified few things:

    
    
      -I put "'google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware',
      " in the top of my MIDDLEWARE_CLASSES settings
    
      -I have the google-cloud-sdk.
    
      -I have in my .profile "export PATH=$PATH:/home/david/google-cloud-sdk/platform"
    
      -I attempt to change the PYTHONPATH to integrated the PATH of google-cloud-sdk, but without success.
    

Pycharm show me a problemwith the import, he know google, but don't know the
end of the import.(appengine.ext)

I have search and I have the ndb module with this path :

    
    
     /home/david/google-cloud-sdk/platform/google_appengine/google/appengine/ext/ndb
    

Somebody can help me?


Answer: The problem is you are trying to use App Engine infrastructure but have not
properly set up the App Engine environment. This is documented in the App
Engine Local Unit Testing page in the [Setting up a testing
framework](https://cloud.google.com/appengine/docs/python/tools/localunittesting#Python_Setting_up_a_testing_framework)
section:

    
    
    sdk_path = '/home/david/google-cloud-sdk/platform/google_appengine'
    sys.path.insert(0, sdk_path)
    import dev_appserver
    dev_appserver.fix_sys_path()
    

