Where to set the GOOGLE_APPLICATION_CREDENTIALS environment variable?

Viewed 1386

I am trying to use Python to call a Google Cloud AI platform training API. The path to my service account key JSON file is "/Users/my_mac_username/service_account_key.json", and I added the export statement in the bash_profile file so that it looks like:

# 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"

However, I still got the error:

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

Besides, I have google-cloud-sdk folder installed. I would like to know in which file I should set the environment variable. Thanks for your help!

1 Answers

Assuming your terminal shell is bash, you have your environment variable setup correctly. The new variable will not be available until you reopen the terminal or run source ~/.bash_profile in the current terminal.

If you are running zsh, add the export in your ~/.zshrc file.

To determine which shell you're currently running, use: echo $SHELL from the command line

Related