我正在尝试使用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 文件夹。请问我应该在哪个文件中设置环境变量?感谢您的帮助!
echo $GOOGLE_APPLICATION_CREDENTIALS
,你会得到正确的数据吗?自从在你的bash_profile中设置了该值后,你是否打开了一个新的控制台? - Brettskisource ~/.bash_profile
来加载您的配置文件或打开一个新的终端窗口。您也可以直接从控制台运行export GOOGLE_APPLICATION_CREDENTIALS="/Users/my_mac_username/service_account_key.json"
。 - Brettskiecho $SHELL
来查看。 - Brettski