Stack Exchange
AttributeError: 'Client' object has no attribute 'query'
I try to implement bigquery in python 2.7 on jupyter notebook. I think my code is correct, but i'm getting the error "AttributeError: 'Client' object has no attribute 'query'"
# Create SQL query using natality data after the year 2000
query = """
SELECT
  weight_pounds,
  is_male,
  mother_age,
  plurality,
  gestation_weeks,
  ABS(FARM_FINGERPRINT(CONCAT(CAST(YEAR AS STRING), CAST(month AS STRING)))) AS hashmonth
FROM
  publicdata.samples.natality
WHERE year > 2000
"""

# Call BigQuery and examine in dataframe
from google.cloud import bigquery
client = bigquery.Client()
df = client.query(query + " LIMIT 100").to_dataframe()
df.head()

The error message i got is:
AttributeErrorTraceback (most recent call last)
<ipython-input-12-caf57b3f137d> in <module>()
      2 from google.cloud import bigquery
      3 client = bigquery.Client()
----> 4 df = client.query(query + " LIMIT 100").to_dataframe()
      5 df.head()

AttributeError: 'Client' object has no attribute 'query'


Try print dir(client) and see what it shows.

Are you running in virtualenv? If not, install virtualenv and the requirements inside virtualenv then run your script.

I'm running in jupyter notebook on Google Cloud Platform AI notebook...

Problem fixed! Just need to update the bigquery via
pip install --upgrade google-cloud-bigquery
