【问题标题】:Setting BiqQuery environment variable Error设置 BiqQuery 环境变量错误
【发布时间】:2020-11-18 06:29:59
【问题描述】:

我一直在关注 Google 的 BigQuery get started 页面,了解如何设置凭据,但仍有一些不正确的地方。这些是我遵循的步骤:

  1. 设置免费服务帐户并创建我的密钥。将其保存到文件夹中。

  2. 在 Anaconda Prompt 中设置环境变量为set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\$Name\OneDrive\Templates\api\BigQuery\creds.json

  3. 在 Python 中:

    from google.cloud import bigquery

    client = bigquery.Client()

这导致了以下错误。我该如何解决?

Traceback (most recent call last):
File "<ipython-input-2-490cf645c3eb>", line 1, in <module>
client = bigquery.Client()

  File "C:\Users\$Name\Anaconda3\lib\site-packages\google\cloud\bigquery\client.py", line 179, in __init__
    project=project, credentials=credentials, _http=_http

  File "C:\Users\$Name\Anaconda3\lib\site-packages\google\cloud\client.py", line 226, in __init__
    _ClientProjectMixin.__init__(self, project=project)

  File "C:\Users\$Name\Anaconda3\lib\site-packages\google\cloud\client.py", line 178, in __init__
    project = self._determine_default(project)

  File "C:\Users\$Name\Anaconda3\lib\site-packages\google\cloud\client.py", line 193, in _determine_default
    return _determine_default_project(project)

  File "C:\Users\$Name\Anaconda3\lib\site-packages\google\cloud\_helpers.py", line 186, in _determine_default_project
    _, project = google.auth.default()

  File "C:\Users\$Name\Anaconda3\lib\site-packages\google\auth\_default.py", line 338, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)

DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

【问题讨论】:

标签: google-bigquery


【解决方案1】:

您是否在设置环境变量的同一 shell 中运行 python?如果您在不同的 shell/tab 中运行,您可能需要导出 GOOGLE_APPLICATION_CREDENTIALS。

【讨论】:

  • 对于未来,像这样的问题,通常是cmets。我在 Anaconda 提示符中为我的基本环境设置了变量。然后我重新启动环境,打开我的 IDE 并尝试在那里执行它。说明不提供非命令行选项。
猜你喜欢
  • 2014-12-03
  • 2015-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-13
  • 2014-12-17
  • 2016-11-09
  • 2019-03-24
相关资源
最近更新 更多