ImportError: No module named google.appengine.ext.

2019-09-10 22:26发布

I'm trying to get google app engine to work on my Raspberry Pi. I keep getting this error.

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

I downloaded google app engine and then ran these commands:

unzip google_appengine_1.9.40.zip 

export PATH=$PATH:/home/pi/google_appengine/

2条回答
干净又极端
2楼-- · 2019-09-10 23:12

The most trivial solution for such errors is to import the required package into you project directory. but to be honest it is not the best way to resolve this one. you may use Google App Engine SDK which will take care of all that headache, or there are another way you can follow:

  1. Create a folder into your project directory and call it lib
  2. Add all required packages into this folder.
  3. Create a .py file and name it appengine_config.py
  4. Add the below code snippets into this file:

    import sys

    import os.path

    sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

appengine_config.py gets loaded every time a new instance is started, and should take care of your modules importing.

Regards.

查看更多
神经病院院长
3楼-- · 2019-09-10 23:22

It appears you're trying to directly execute your main.py as a standalone application, which is not how GAE app code works.

You're supposed to get the development server (from the SDK you downloaded) to execute your app code on your development machine (on GAE it's the GAE infra doing that). See Using the Local Development Server.

查看更多
登录 后发表回答