我一直在关注Google的BigQuery get started页面,以了解如何设置凭据,但是仍然存在一些错误。这些是我遵循的步骤:
设置免费的服务帐户并创建我的密钥。将其保存到文件夹。
在Anaconda Prompt中将环境变量设置为set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\$Name\OneDrive\Templates\api\BigQuery\creds.json
。
在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
答案 0 :(得分:0)
您是否在与设置环境变量相同的shell中运行python?如果您在其他shell /标签中运行,则可能需要导出GOOGLE_APPLICATION_CREDENTIALS。