简体   繁体   English

ImportError:AppEngine 中没有名为 cloud 的模块,python

[英]ImportError: No module named cloud in AppEngine, python

i have a problem when i try to execute my script.py througth appengine just with the library "from google.cloud import bigquery", i try some solutions but i have not had a success way, i show you the scripts which i use to execute this script.当我尝试仅使用库“from google.cloud import bigquery”执行我的 script.py 通过 appengine 时遇到问题,我尝试了一些解决方案,但我没有成功的方法,我向您展示了我使用的脚本执行这个脚本。

This is my script:这是我的脚本:

import json
import datetime
import webapp2
from google.cloud import bigquery
from google.appengine.ext import vendor
vendor.add('lib')

filename = "example.json"

def date_format(time):
        if time.find(".") != -1:
            time = time[:time.find(".")]
        date = datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S")
        return date.strftime("%Y%m%d")


class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        with open(filename) as file:
            array = []
            jsonData = json.load(file)
            d = str(date_format(jsonData['e']))
            self.response.write('Hello AppEngine from script! :: '+d)

            client = bigquery.Client()

            QUERY = (           
                    'SELECT field FROM `table` WHERE date='+d+' LIMIT 10'
                    )
            query_job = client.query(QUERY)
            rows = query_job.result()
            for row in rows:
                print(row.field)


app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

This is my app.yaml:这是我的应用程序。yaml:

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /.*
  script: main.app

This is my requirements.txt:这是我的 requirements.txt:

google-api-python-client
google-cloud

I have a lib directory with the bigquery library: google_cloud_bigquery-1.24.0.dist-info.我有一个带有 bigquery 库的 lib 目录:google_cloud_bigquery-1.24.0.dist-info。 and others libraries with google_cloud和其他带有 google_cloud 的库

I dont know if my code is correct, because i have saw some solutions but anything helpme to run script with appengine.我不知道我的代码是否正确,因为我已经看到了一些解决方案,但任何东西都可以帮助我使用 appengine 运行脚本。

i hope you can help me please.我希望你能帮助我。

This is the script with python 3这是 python 3 的脚本

import google.cloud.bigquery as bigquery
# [START gae_python37_app]
from flask import Flask
from google.appengine.ext import vendor
vendor.add('lib')


# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)

@app.route('/')
def hello():
    """Return a friendly HTTP greeting."""
    client = bigquery.Client()
    QUERY = (           
            'SELECT ev FROM `table` WHERE f="20200201" LIMIT 10'
            )
    query_job = client.query(QUERY)
    rows = query_job.result()
    for row in rows:
        return row.ev


if __name__ == '__main__':
    # This is used when running locally only. When deploying to Google App
    # Engine, a webserver process such as Gunicorn will serve the app. This
    # can be configured by adding an `entrypoint` to app.yaml.
    app.run(host='127.0.0.1', port=8080, debug=True)
# [END gae_python37_app]

You are using App Engine Standard's Python 2.7 runtime.您正在使用 App Engine Standard 的 Python 2.7 运行时。 This runtime does not allow you to specify dependencies with a requirements.txt file.此运行时不允许您使用requirements.txt文件指定依赖项。

Instead, you should follow this guide to vendor any dependencies like google-cloud-bigquery along with your application: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27相反,您应该按照本指南向您的应用程序提供任何依赖项,例如google-cloud-bigqueryhttps://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27

You may need to remove any existing lib directory entirely and start again.您可能需要完全删除任何现有的lib目录并重新开始。

Also, note that the google-cloud package is deprecated, you should not use it.另外,请注意google-cloud package 已弃用,您不应使用它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM