使用google.cloud时没有名为云的模块导入bigquery [英] No module named cloud while using google.cloud import bigquery

查看:670
本文介绍了使用google.cloud时没有名为云的模块导入bigquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个应用引擎应用程序来使用谷歌应用程序引擎启动器将数据加载到bigquery表中,但是当我在本地主机或云上运行它时,我使用google.cloud导入了bigquery错误消息日志文件。我已经安装了谷歌云客户端库,但它仍然给我同样的错误。请在下面看到我使用的代码

--- main.py文件包含

  import argparse 
导入时间
从google.cloud导入uuid

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())
$ b $ job = bigquery_client.load_table_from_storage(
job_name,table,source)

job.begin()

wait_for_job(job)

print('Loaded {} rows into {}:{}。'。格式(
job.output_rows,dataset_name,table_name))


def wait_for_job(job):
,而True:
job.reload()
如果job.state =='完成':
如果job.error_result:
提升RuntimeError(job.error_result)
返回
时间。 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文件包含以下代码

 应用程序:mycloudproject 
版本:1
运行时:python27
api_version:1
线程安全:是

处理程序:
- url:/favicon\.ico
static_files:favicon.ico
上传:favicon \.ico

- url:。*
脚本:main.app

请让我知道缺少什么或者我在这里做错了什么? / p>

解决方案

这可能有点棘手。 Google Cloud使用新的Python名称空间格式(如果您查看源代码,您会注意到目录结构中没有 __ init __。py )。



这在Python 3.3中被 PEP-420



幸运的是,在Python 2.7中,您可以通过避免隐式导入来轻松解决此问题。只需将它添加到文件的顶部即可:



from __future__ import absolute_import



希望有所帮助。


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 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 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?

解决方案

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).

This was changed in Python 3.3 with PEP-420

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

Hope that helps.

这篇关于使用google.cloud时没有名为云的模块导入bigquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆