How to install gcp in Python?

前端 未结 6 2064
长情又很酷
长情又很酷 2021-01-15 14:55

Lots of the BigQuery examples begin with:

import gcp.bigquery as bq

But I get ImportError: No module named gcp.bigquery whenev

6条回答
  •  耶瑟儿~
    2021-01-15 15:14

    If you're accessing BigQuery in python, you can do that using the gcloud library.

    First, install the gcloud library:

    $ pip install --upgrade gcloud
    

    Then, after setting up your auth and project info, you can make api calls in python like this (adapted from the gcloud-python docs):

    from gcloud import bigquery
    
    client = bigquery.Client()
    datasets, next_page_token = client.list_datasets()
    print([dataset.name for dataset in datasets])
    

    (As someone mentioned previously, you can also do it using the google-api-python-client.)

    License: Apache 2

提交回复
热议问题