Google App Engine: "No module named google.appengine.ext"

11,749

Solution 1

I had the same problem when testing my app. I found that my /usr/local/google_appengine contained the google python module, so I added that path to my $PYTHONPATH environment variable. You can do this in 2 ways:

  1. In your console, type export PYTHONPATH="$PYTHONPATH:/usr/local/google_appengine". This will add it to your PYTHONPATH for this console session.

  2. In your shell profile file (perhaps ~/.bash_profile), add a line like this:

    export PYTHONPATH="$PYTHONPATH:/usr/local/google_appengine"
    

    Then either open a new console session or reload your profile with source ~/.bash_profile (or whatever your file is)

You may have to modify this because a) your "google_appengine" folder is in a different location (not /usr/local) or b) your OS separates paths differently (I think windows uses ; instead of : -- I'm on a Mac)

Solution 2

I would like to add a case that I have faced. My OS is MAC.

The Google App Engine would create a link under /usr/local/google_appengine.

I added the above path to PYTHONPATH, it still don't work. After some trail, I found I had installed protobuf which is also under development of google, please check

https://developers.google.com/protocol-buffers/docs/pythontutorial

It will create a folder under side_packages also named google. So if you try to import google, it is actually importing protobuf.

So one possible solution for this is temporarily uninstall protobuf:

pip uninstall protobuf

Solution 3

It seems that the problem come from the directory /google_appengine that is not always at the right spot, so python cannot find it (through PYTHONPATH).

  1. Find the location of the google_appengine directory by running

    find / -name google_appengine -type d

  2. Once you found it (e.g. : /usr/lib/google-cloud-sdk/platform/google_appengine), run:

    export PYTHONPATH=:/usr/lib/google-cloud-sdk/platform/google_appengine

This solved my problem.

Solution 4

It's not the answer, but can you try adding the following code to debug:

import logging

import google

logging.info("google path: {}.".format(google.__file__))

Compare this path to the location of the App Engine SDK.

Solution 5

Following code will print all google python lib paths

import google
print "google path: {}.".format(google.__path__)

running the code on my machine prints this

google path: ['/usr/local/Cellar/protobuf/2.6.1/libexec/lib/python2.7/site-packages/google', '/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google'].

this is not the same as looking for google appengine installation directories. On my mac, the installer creates sym links

/usr/local/google_appengine

incase you are unit testing, you probably need to add the path to your code

import sys
sys.path.insert(1, '/usr/local/google_appengine')
sys.path.insert(1, '/usr/local/google_appengine/lib/yaml/lib')
Share:
11,749
askingdoesntkill
Author by

askingdoesntkill

Updated on June 14, 2022

Comments

  • askingdoesntkill
    askingdoesntkill almost 2 years

    Im getting this error when testing my main.py GAE application:

    Traceback (most recent call last):
      File "main.py", line 4, in <module>
        from google.appengine.ext import db
    ImportError: No module named google.appengine.ext
    

    I read a lot about it but i can´t find the answer...any ideas or help? Thank you guys!!

  • Ben
    Ben almost 10 years
    So this worked for me, but I had to then pip install every library that was missing. It didn't make all the GAE builtin libraries (e.g. Jinja2) available. So kudos for solving the specific issue, but the bigger problem still unsolved. Kind of weak-ass of Google tho, since it seems that a lot of people are having this problem in spite of following the installation instructions...
  • Shruti Kar
    Shruti Kar almost 4 years
    find / -name google_appengine -type d isn't returning anything. Or rather is taking very long to find the file. what may be the reason?