Reputation: 2184
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.
Upvotes: 2
Views: 9614
Reputation: 1572
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
Upvotes: 4
Reputation: 39824
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).
Upvotes: 7