Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!!

like image 702
askingdoesntkill Avatar asked Mar 23 '13 21:03

askingdoesntkill


4 Answers

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)

like image 146
rmosolgo Avatar answered Oct 12 '22 05:10

rmosolgo


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

like image 40
hugle Avatar answered Oct 12 '22 06:10

hugle


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.

like image 43
gowithefloww Avatar answered Oct 12 '22 05:10

gowithefloww


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.

like image 29
Takashi Matsuo Avatar answered Oct 12 '22 05:10

Takashi Matsuo