使用 google.cloud import bigquery 时没有名为 cloud 的模块 [英] No module named cloud while using google.cloud import bigquery
问题描述
我已经构建了一个应用引擎应用程序来使用谷歌应用引擎启动器将数据加载到 bigquery 表中,但是当我在本地主机或云上运行它时,我在使用 google.cloud import bigquery 错误消息时得到名为 cloud 的 No module日志文件.我已经安装了谷歌云客户端库,但它仍然给我同样的错误.请看下面我使用的代码
i have built an app engine application to load data into bigquery table using google app engine launcher but when I run it on local host or on the cloud i get the No module named cloud while using google.cloud import bigquery error message in log file. I have installed the google cloud client library but it is still giving me the same error. please see below the code I am using
---main.py 文件包含
---main.py file contains
import argparse
import time
import uuid
from google.cloud import bigquery
def load_data_from_gcs(dataset_name, table_name, source):
bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset(dataset_name)
table = dataset.table(table_name)
job_name = str(uuid.uuid4())
job = bigquery_client.load_table_from_storage(
job_name, table, source)
job.begin()
wait_for_job(job)
print('Loaded {} rows into {}:{}.'.format(
job.output_rows, dataset_name, table_name))
def wait_for_job(job):
while True:
job.reload()
if job.state == 'DONE':
if job.error_result:
raise RuntimeError(job.error_result)
return
time.sleep(1)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('Test')
parser.add_argument('mytable')
parser.add_argument('gs://week/geninfo.csv')
args = parser.parse_args()
load_data_from_gcs(
args.dataset_name,
args.table_name,
args.source)
--app.yaml 文件包含以下代码
--app.yaml file contains the following code
application: mycloudproject
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.ico
- url: .*
script: main.app
请告诉我缺少什么或者我在这里做错了什么?
Please let me know what is missing or if I am doing something wrong here?
推荐答案
这可能有点棘手.Google Cloud 使用新的 Python 命名空间格式(如果您查看源代码,您会注意到目录结构中没有 __init__.py
).
This can be a bit tricky. Google Cloud uses the new Python namespace format (if you look at the source you'll notice that there's no __init__.py
in the directory structure).
这在 Python 3.3 中被更改为 PEP-420
This was changed in Python 3.3 with PEP-420
幸运的是,在 Python 2.7 中,您可以通过避免隐式导入轻松解决此问题.只需将此添加到文件顶部:
Fortunately in Python 2.7 you can fix this easily by avoiding implicit imports. Just add this to the top of your file:
from __future__ import absolute_import
希望有所帮助.
这篇关于使用 google.cloud import bigquery 时没有名为 cloud 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!