Google appengine项目第三方库导入错误

时间:2017-08-08 15:22:38

标签: python python-2.7 google-app-engine jinja2 webapp2

我正在Google App Engine标准环境Python 2.7中开发一个app-engine项目。 主要是我的应用程序使用webapp2进行请求处理(WSGI协议)和jinja2作为python框架工作。

尝试导入google-cloud-bigquery,google-auth,google-oauth2时,我没有收到模块名称错误。

这些是迄今为止我尝试解决的解决方案,但其中任何一方都无法成功。

以上是[问题]:Google Cloud BigQuery Import not working in app engine project

第二个[问题]:Error importing Google Cloud Bigquery api module in python app

Google文档[链接]:https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27

的app.yaml

runtime: python27
threadsafe: true

libraries:
- name: webapp2
 version: latest
- name: jinja2
  version: latest
- name: PIL
  version: latest

handlers:
- url: /fav_icon
  static_dir: fav_icon

- url: /fav_icons
  static_dir: fav_icons

- url: /css
  static_dir: css
  mime_type: 'text/css'

 - url: /js
   static_dir: js

- url: /.*
  script: main.app

main.py

from __future__ import absolute_import
import sys
sys.path.insert(0, 'lib')
import os
import jinja2
import webapp2
import csv
from jinja2 import Template
import flask
from google.cloud import bigquery
import google.auth
from google.oauth2 import service_account
JINJA_ENVIRONMENT = jinja2.Environment(
# TODO: to add other directories here that contains the templates.
loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__),'templates')),
extensions=['jinja2.ext.autoescape'],
autoescape=True)

class Bigquery(webapp2.RequestHandler):
     """docstring for ."""
     def get(self):
         ser_acc_file_path = os.getcwd()+ str('/file_name.json')
         credentials = service_account.Credentials.from_service_account_file(ser_acc_file_path)
         if credentials.requires_scopes:
           credentials =credentials.with_scopes(['https://www.googleapis.com/auth/bigquery'])
          bigquery_client = bigquery.Client(project='project_123', credentials=credentials)
          query_results = bigquery_client.run_sync_query("""SELECT * FROM `project_123.dataset.table` LIMIT 100;""")
          query_results.use_legacy_sql = False
          query_results.run()
          rows = query_results.fetch_data()
          self.response.headers['Content-Type'] = 'text/plain'
          self.response.write(str(row))
app = webapp2.WSGIApplication(routes=[
('/',Bigquery))],debug=True)

if __name__ == '__main__':
main()

所有第三方库都使用pip安装在lib目录中。

0 个答案:

没有答案
相关问题