[英]Can't import Datastore from google.cloud
I'm trying to create a basic web app using Flask and Google Datastore to make myself to Google Cloud. 我正在尝试使用Flask和Google Datastore创建一个基本的Web应用程序,以使自己进入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
. 虽然,当我部署我的应用程序时,出现错误500,详细信息是Python无法导入数据存储区:
ImportError: No module named cloud
。
Here is my app.yaml
: 这是我的
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: 我的
main.py
开始如下:
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: 最后,我的
requirements.txt
是以下内容:
Flask
google-cloud
click
When I deploy my app (using gcloud app deploy
) and get to my site, I get my error 500. 当我部署应用程序(使用
gcloud app deploy
)并到达我的网站时,出现错误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. 我不明白为什么我不能
from google.cloud import datastore
使用from google.cloud import datastore
因为这正是Google在他们的教程中所做的...我一定会遗漏一些东西,但找不到。
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. 您需要(以匹配您的导入语句)的客户端库是
google-cloud-datastore
,但您的requirements.txt
文件中没有列出该客户端库。
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). 旁注:您的
app.yaml
文件表示您的应用程序是标准的en GAE应用程序,对于该应用程序,您已经拥有已包含在SDK中的优化的Google数据存储NDB客户端库库(如果您没有特定的理由选择通用)。
You do not specify env: flex
so you are using Standard Environment. 您未指定
env: flex
因此您正在使用标准环境。 Here it is described for flex yaml and here it doesn't appear for standard yaml. 此处针对flex yaml进行了说明,而针对标准yaml则未出现。
This is important because google-cloud is not supported for Standard Environment. 这很重要,因为标准环境不支持google-cloud。 google-cloud's repository :
google-cloud的存储库 :
These libraries currently do not run on Google App Engine Standard
这些库当前无法在Google App Engine标准上运行
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: Dan Cornilescu提到的有关NDB Client的链接是针对标准环境的官方解决方案,在官方文档中找不到几个示例:
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 https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/ndb和https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/多租户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.