0

I was following Google's BigQuery get started page on how to set the credentials, but something is still incorrect. These are the steps I followed:

  1. Set up a free Service Account and created my key. Saved it to a folder.

  2. Set the environment variable in Anaconda Prompt as set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\$Name\OneDrive\Templates\api\BigQuery\creds.json.

  3. In Python:

    from google.cloud import bigquery

    client = bigquery.Client()

This resulted in the following error. How do I fix it?

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
Jack Armstrong
  • 1,182
  • 4
  • 26
  • 59
  • Does this answer your question? [How to Auth to Google Cloud using Service Account in Python?](https://stackoverflow.com/questions/44328277/how-to-auth-to-google-cloud-using-service-account-in-python) – Nick_Kh Jul 29 '20 at 07:17

1 Answers1

0

Were you running the python in the same shell as where you set the environment variable? you may need to export GOOGLE_APPLICATION_CREDENTIALS if you are running in a different shell/tab.

Lei Wang
  • 29
  • 6
  • For the future, questions like this one, are normally comments. I set the variable in the Anaconda prompt for my base environment. Then I restarted the environment, opened up my IDE and tried to execute it there. The instructions do not provide a non-command line option. – Jack Armstrong Jul 28 '20 at 18:31