简体   繁体   English

无法从google.cloud导入数据存储

[英]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/ndbhttps://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/多租户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gitlab CI Runner无法以Python导入Google.Cloud - Gitlab CI Runner can't import Google.Cloud in Python 从 google.cloud 导入数据存储给出“ImportError:无法导入名称“collections_abc”” - from google.cloud import datastore gives 'ImportError: cannot import name 'collections_abc'' 无法从google.cloud导入存储空间 - Unable to import storage from google.cloud 来自google.cloud导入语言ModuleNotFoundError:没有名为“ google.cloud”的模块 - from google.cloud import language ModuleNotFoundError: No module named 'google.cloud' 无法导入“从 google.cloud 导入 bigquery” - unable to import "from google.cloud import bigquery" Google Cloud Dataflow 无法导入“google.cloud.datastore” - Google Cloud Dataflow can't import 'google.cloud.datastore' 来自google.cloud导入firestore ModuleNotFoundError:没有名为'google'的模块 - from google.cloud import firestore ModuleNotFoundError: No module named 'google' 从google.cloud导入bigquery ModuleNotFoundError:没有名为“ google”的模块 - from google.cloud import bigquery ModuleNotFoundError: No module named 'google' 无法在 python 脚本中导入 google.cloud 模块 - Can not import google.cloud module in python script 如何从 google.cloud 导入 bigquery 模块 - how to import bigquery module from google.cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM