No module named 'google'

635 views
Skip to first unread message

Keith Preston

unread,
Oct 19, 2016, 4:21:23 PM10/19/16
to Google App Engine

I've been following some of the examples, but seem to have problems importing from the google.appengine.api once I've deployed to GAE.     Adding some debugging the error is No module named 'google'


Do I need to do anything special in my main.py, app.yaml or requirement.txt to get the google.appengine.api?   I can't seem to find details about this in the documentation


main.py

try:

    from google.appengine.api import urlfetch

except Exception as e:

    error = str(e)


app.yaml

runtime: python

vm: true

entrypoint: gunicorn -b :$PORT main:app

runtime_config:

  python_version: 3


requirements.txt

Flask==0.11.1

gunicorn==19.6.0

Evan Jones

unread,
Oct 20, 2016, 3:59:03 PM10/20/16
to Google App Engine
You are running a Flexible Environment virtual machine here. This environment does not include the App Engine libraries (nor does it recommend it, unless you need to port an existing app). You should just use urllib2 or the requests library directly, since you are running on a VM. You have no need for the urlfetch API.


There is a hint, although it doesn't explicitly say it, that if you are writing a new application, you probably shouldn't use the python-compat runtime in this document: https://cloud.google.com/appengine/docs/flexible/python/migrating-an-existing-app

Alternatively: Use the "Standard Environment" and you won't have this problem.

Nicholas (Google Cloud Support)

unread,
Oct 24, 2016, 2:49:33 PM10/24/16
to Google App Engine
Hello Keith,

As mentioned by Evan, you are indeed deployed your application to the App Engine flexible environment which generally does not include the App Engine libraries.  The exception is as Evan mentioned the python-compat runtime which can be used with vm: true (to run in the flexible environment).  Though you won't have Python 3 here, you'll have access to the App Engine APIs while in the flexible environment.

If you wish to use Python 3, it will have to be in the flexible environment at the moment and will not have access to the built-in App Engine APIs.  You will however be able to use the RESTful equivalent for those services which have them like Cloud Datastore and Task Queues to name a few.

If Python 3 is not really a necessity for your application, you may want to consider deploying to the standard environment (Python 2.7) to fully appreciate the built-in APIs.

If you need more specific information about each environment, please give more details about your application's needs so that we can provide more effective advice.  Happy coding!

On Wednesday, October 19, 2016 at 4:21:23 PM UTC-4, Keith Preston wrote:
Reply all
Reply to author
Forward
0 new messages