-2

I need to run BigQuery on Python but the Google BigQuery module doesn't exist

from google.cloud import bigquery
client = bigquery.Client(project='PROJECT_ID')
query = "SELECT...."
dataset = client.dataset('dataset')
table = dataset.table(name='table')
job = client.run_async_query('my-job', query)
job.destination = table
job.write_disposition= 'WRITE_TRUNCATE'
job.begin()

Do you guys know how to do the connection?

Nhan Nguyen
  • 410
  • 2
  • 12
  • 1
    what you mean the module doesn't exist? what error are you seeing? – Willian Fuks Sep 27 '17 at 17:24
  • 1
    Agree with Willian - we need to see the error. Did you install `bigquery`? – HFBrowning Sep 27 '17 at 17:24
  • Possible duplicate of [No module named cloud while using google.cloud import bigquery](https://stackoverflow.com/questions/40469762/no-module-named-cloud-while-using-google-cloud-import-bigquery) – HFBrowning Sep 27 '17 at 20:08
  • 1
    On ImportError: No module named google.cloud . Please refer [this](https://stackoverflow.com/questions/44397506/importerror-no-module-named-google-cloud) . #Suggestion - Its worth spending few mins searching your question on web or SO before asking, Most of the time its already answered somewhere else! – Rishi Sep 27 '17 at 20:51

4 Answers4

3

Looks like you do not have bigquery module installed, you could install it with -

pip install --upgrade google-cloud-bigquery

Ref - Installing the client library

Rishi
  • 5,323
  • 7
  • 33
  • 43
1

As per Document, need to install client library for bigquery.

Dharmesh Fumakiya
  • 2,070
  • 1
  • 10
  • 17
  • tks, found it: https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-python – Dee Oct 31 '18 at 03:30
0

One thing that you need to correct is to setup credentials to connect your big query with PYTHON. You will also need to setup environment variable GOOGLE_APPLICATION_CREDENTIALS pointing towards the location of your credential file .

0

If your problem is on the connection to BigQuery: client = bigquery.Client() creates the connection using your default credentials. Default credentials can be set on terminal using gcloud auth login. More on that you can see here: https://cloud.google.com/sdk/gcloud/reference/auth/login

If your problem it to install the library, consider running on terminal pip install --upgrade google-cloud-bigquery -- library docs can be found here: https://googleapis.dev/python/bigquery/latest/index.html

Dharman
  • 26,923
  • 21
  • 73
  • 125
Fred
  • 31
  • 3