在哪里设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量?

时间:2021-03-07 06:48:46

标签: environment-variables google-authentication google-api-python-client

我正在尝试使用 Python 调用 Google Cloud AI 平台训练 API。我的服务帐户密钥 JSON 文件的路径是“/Users/my_mac_username/service_account_key.json”,我在 bash_profile 文件中添加了导出语句,使其看起来像:

# Setting PATH for Python 3.8
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH
export GOOGLE_APPLICATION_CREDENTIALS="/Users/my_mac_username/service_account_key.json"

但是,我仍然收到错误:

google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.

此外,我安装了 google-cloud-sdk 文件夹。我想知道我应该在哪个文件中设置环境变量。感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

假设您的终端 shell 是 Sum,您的环境变量设置正确。在您重新打开终端或在当前终端中运行 from django.db.models import DecimalField, F Sales.objects.values('date').annotate(total_sum=Sum(F('price') * F('quantity'), output_field=DecimalField())) 之前,新变量将不可用。

如果您正在运行 zsh,请将导出添加到您的 bash 文件中。

要确定您当前运行的是哪个 shell,请在命令行中使用:source ~/.bash_profile