【问题标题】:AttributeError: 'Client' object has no attribute 'query'AttributeError:“客户端”对象没有属性“查询”
【发布时间】:2019-07-03 16:56:15
【问题描述】:

我尝试在 jupyter notebook 上的 python 2.7 中实现 bigquery。我认为我的代码是正确的,但我收到错误“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()

我得到的错误信息是:

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'

【问题讨论】:

  • 试试print dir(client) 看看它显示了什么。
  • 你在 virtualenv 中运行吗?如果没有,请在 virtualenv 中安装 virtualenv 和要求,然后运行您的脚本。
  • 我在 Google Cloud Platform AI notebook 上的 jupyter notebook 中运行...

标签: python-2.7 google-bigquery python-bigquery


【解决方案1】:

问题已解决!只需要通过更新 bigquery pip install --upgrade google-cloud-bigquery

【讨论】:

    猜你喜欢
    • 2019-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 2015-10-13
    • 1970-01-01
    • 2018-11-23
    • 2016-04-03
    相关资源
    最近更新 更多