Google App Engine: “No module named google.appengi

2019-05-02 11:26发布

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

5条回答
beautiful°
2楼-- · 2019-05-02 11:37

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')
查看更多
放荡不羁爱自由
3楼-- · 2019-05-02 11:40

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

查看更多
仙女界的扛把子
4楼-- · 2019-05-02 11:51

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)

查看更多
何必那么认真
5楼-- · 2019-05-02 11:51

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.

查看更多
时光不老,我们不散
6楼-- · 2019-05-02 11:53

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.

查看更多
登录 后发表回答