25
votes

after runing this code,I found import error:-

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication([('/', MainPage)],debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

how to use google.apengine.ext

8
How did you install it? Check that the it's on your PYTHONPATH. - StoryTeller - Unslander Monica
If you are trying to run it in interactive Python environment, you will have to modify sys.path as mentioned in comments below. If you plan to serve the web application then you should run your app using dev_appserver.py. Command would be <path-to-google-sdk>/platform/google_appengine/dev_appserver.py app.yaml - Akshar Raaj
I don't know why you removed my answer. I had exactly the same error and having file google.py caused this problem. So for me is answer. May be is not answer to your exact case, but it was answer to my case. Also I had absolutely the same message as error : "python import error “No module named appengine.ext” , so please return my answer back. Regards. - makkasi

8 Answers

18
votes

It looks like the App Engine SDK is not installed, or at least the Python runtime cannot find it.

read and follow the instructions here: https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python

They tell you, how to install App Engine SDK for Python.

19
votes
import sys
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine')
sys.path.insert(1, '/Users/<username>/google-cloud-sdk/platform/google_appengine/lib/yaml/lib')
sys.path.insert(1, 'lib')

if 'google' in sys.modules:
    del sys.modules['google']

this solves the problems for me

10
votes

Try:

import google
print google.__path__

to see what exactly you're importing.

2
votes

I had this same issue because I pip installed gcloud before downloading and installing the SDK. The pip install created a python package google which didn't contain the appengine submodule (which is found in the SDK folder). I uninstalled the gcloud and related packages. Then just pip installed the google-cloud-bigquery which is the only package I needed from gcloud. Everything works fine now.

1
votes

I faced similar error while calling Google Analytics API using AWS Lambda.

Workaround from (Schweigi1) helped me.

import googleapiclient
from googleapiclient.discovery_cache.base import Cache

class MemoryCache(Cache):
    _CACHE = {}

    def get(self, url):
        return MemoryCache._CACHE.get(url)

    def set(self, url, content):
        MemoryCache._CACHE[url] = content

Usage:

service = googleapiclient.discovery.build("analyticsreporting", "v4", http=http, credentials=credentials,cache=MemoryCache())

Hope this helps someone who is facing this issue in AWS Lambda.

1
votes

First possible reason:

you don't install the python library in google cloud sdk, so you can run in cmd (as administrator):

gcloud components install app-engine-python.

Second possible reason:

your IDE is not success get into google libraries, they exist in:

C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine

or in:

C:\Users\[your user]\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine

You can see in attached link explain how to add these libraries to IDE external libraries: https://stackoverflow.com/a/24206781/8244338

0
votes

I got this error in python:

from google.appengine.api import search
ImportError: No module named appengine.api

I thought this would be something along the similar lines of what is happening in this thread.

So, my solution was to run "dev_appserver.py 'your yaml file' ". I got this solution following the below links:

1) https://cloud.google.com/appengine/docs/standard/python/tools/using-local-server

2) https://www.youtube.com/watch?v=BdqUY8lCuBI

Hope this helps!

-1
votes

check if you named some file google.py :) in the same package, because this can shadow the import of google.appengine.ext. I had the same error:

python import error “No module named appengine.ext”

and deleteting the file solved the problem.