I'm running into this weird error with a Cloud Endpoints app that I'm just starting to write. I'm not sure if Google changed their libraries or not, but I think this should work?
In my app.yaml I've got...
libraries:
- name: webapp2
version: "latest"
- name: endpoints
version: "latest"
And then in my main.py I call:
import endpoints
Result:
ImportError: No module named endpoints
Why would app engine be telling me that endpoints doesn't exist? I can see the endpoints folder in the directory itself...
I got the same thing on a fresh install of the SDK (previously worked).
You need to explicitly add the relevant GAE libraries to your PYTHONPATH.
For example if you're using virtualenvwrapper (you should be):
$ add2virtualenv /path/to/google-cloud-sdk/platform/google_appengine/lib/endpoints-1.0
$ add2virtualenv /path/to/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0
Related
I'm trying to create a basic web app using Flask and Google Datastore to make myself to Google Cloud. Though, when I deploy my app, I get an Error 500, the details being that Python can't import Datastore : ImportError: No module named cloud.
Here is my app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: .*
script: main.app
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
- name: flask
version: 0.12
My main.py starts like follows:
from __future__ import absolute_import
# Standard imports
import time
import logging
import json
import threading
# Flask framework
from flask import request
from flask import Flask
# Google Cloud features
from google.cloud import datastore
# the following replaces requests
from google.appengine.api import urlfetch
Finally, my requirements.txt is the following:
Flask
google-cloud
click
When I deploy my app (using gcloud app deploy) and get to my site, I get my error 500.
I don't understand why I can't use from google.cloud import datastore since it's what Google does in their tutorial... I must be missing something but I can't find what.
Any help would be appreciated.
From Installing the client library:
pip install --upgrade google-cloud-datastore
The client library you need (to match your import statement) is google-cloud-datastore, but you don't have that listed in your requirements.txt file.
Side note: your app.yaml file indicates your app is a standard env GAE app one, for which you have the optimized Google Datastore NDB Client Library library available, already included in your SDK (if you don't have specific reasons for choosing the generic one instead).
You do not specify env: flex so you are using Standard Environment. Here it is described for flex yaml and here it doesn’t appear for standard yaml.
This is important because google-cloud is not supported for Standard Environment. google-cloud’s repository:
These libraries currently do not run on Google App Engine Standard
Link mentioned by Dan Cornilescu about the NDB Client is an oficial solution for standard environment and few examples can be found in the oficial documentation:
https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/ndb and https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/multitenancy
I am using google-auth to allow firebase authentication in my GAE project.
Everything works fine when I run the code locally using dev_appserver.py or when I deploy it to google app engine.
But I get this ImportError exceptions when I try to use Django's manage.py script to create/run migrations.
ImportError: Could not import 'firebase.authentication.FirebaseAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named auth.transport.requests.
The google-auth module is installed under lib directory and has this structure:
- lib
- google
- auth
- oauth2
These import cause the ImportErrors:
import google.auth.transport.requests
from google.oauth2 import id_token
My guess is that there might be naming conflicts as other imports work fine.
Please help!
If you want to use 3rd party libraries that are not included in this list, then you'll have to add them manually since you have done that by adding lib folder and including all the package folder follow these steps.
Create your_app_directory/appengine_config.py file.
Add these following lines inside that file
from google.appengine.ext import vendor
vendor.add('lib')
This should solve the import error problem.
I am using a couple of google libs in order to authenticate with firebase in a Python + GAE app.
I have configured the requirements.txt with the following content:
google-auth==1.0.1
requests==2.14.2
requests-toolbelt==0.7.1
This is what I am importing:
import google.auth.transport.requests
When I run pip install, they do get installed locally and I get no errors.
local libs screenshot
But when I try to deploy this application to Google App Engine, all those external libs get the same errors. GAE doesn't find the files:
ImportError: No module named auth.transport.requests
You need to provide your library directory to the google.appengine.ext.vendor.add() method.
Create a file named appengine_config.py in the same folder as your app.yaml file.
Edit the appengine_config.py file and provide your library directory to the vendor.add() method.
# appengine_config.py
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27#installing_a_third-party_library
I'm running Django locally through Google App Engine's dev_appserver.py ./ and when I add this one line to my script:
from google.appengine.ext import deferred
I get the error: ImportError: No module named webapp2 from the deferred module.
I tried adding this to my libraries in app.yaml:
- name: webapp2
version: latest
But that doesn't work either. I feel like it doesn't make sense to use webapp2 when I'm running Django... Is it not possible to use deferred with Django on Google App Engine?
I'm trying to queue Django's send_mail() for a contact form, and I don't want the User to have to wait for it to be sent.
Not sure if this helps, but here's part of my Python Path which is displayed with the import error:
'/usr/local/google-cloud-sdk/platform/lib/MySQLdb-1.2.5',
'/usr/local/google-cloud-sdk/platform/lib/django-1.4',
'/usr/local/google-cloud-sdk/platform/lib/webapp2-2.5.2',
'/usr/local/google-cloud-sdk/platform/lib/protorpc-1.0',
'/usr/local/google-cloud-sdk/platform/lib/webob-1.1.1',
'/usr/local/google-cloud-sdk/platform/lib/yaml-3.10'
As you can see, it is loading webapp2 into the python path.
I have a demo application written in Python and running on Google App Engine. This app has 3 modules. I added a configuration file to configure module's routing but it's not working. This file called dispatch.yaml looks like this:
application: dotted-lexicon-638
dispatch:
- url: "dotted-lexicon-638.appspot.com/"
module: default
- url: "dotted-lexicon-638.appspot.com/list*"
module: list
- url: "dotted-lexicon-638.appspot.com/logs*"
module: logs
I deployed this file using "appcfg.py update_dispatch project_dir" command
if you go to "http://list.dotted-lexicon-638.appspot.com" and "http://logs.dotted-lexicon-638.appspot.com"
you can see that both modules are working.
Am I missing something?
When you use a path for module routing, it doesn't mean that path maps to the root of the module it just determines which module gets a chance to handle the request. Unless you have code in your list module handling /list, then it will 404.