[英]Jenkins cloud : ImportError: No module named selenium (Python)
[英]ImportError: No module named cloud in AppEngine, python
当我尝试仅使用库“from google.cloud import bigquery”执行我的 script.py 通过 appengine 时遇到问题,我尝试了一些解决方案,但我没有成功的方法,我向您展示了我使用的脚本执行这个脚本。
这是我的脚本:
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)
这是我的应用程序。yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
这是我的 requirements.txt:
google-api-python-client
google-cloud
我有一个带有 bigquery 库的 lib 目录:google_cloud_bigquery-1.24.0.dist-info。 和其他带有 google_cloud 的库
我不知道我的代码是否正确,因为我已经看到了一些解决方案,但任何东西都可以帮助我使用 appengine 运行脚本。
我希望你能帮助我。
这是 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]
您正在使用 App Engine Standard 的 Python 2.7 运行时。 此运行时不允许您使用requirements.txt
文件指定依赖项。
相反,您应该按照本指南向您的应用程序提供任何依赖项,例如google-cloud-bigquery
: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
您可能需要完全删除任何现有的lib
目录并重新开始。
另外,请注意google-cloud
package 已弃用,您不应使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.