pyds_learner
pyds_learner

Reputation: 519

Setting environment variable in python for google bigquery in Mac

Before calling the Jupyter Notebook, i run the below code in Terminal for Google Application Credentials :

export GOOGLE_APPLICATION_CREDENTIALS="/Users/mac/Desktop/Bigquery-Key.json"

Then set the below configuration in Jupyter Notebook :

%load_ext google.cloud.bigquery
# Imports the Google Cloud Client Library 
from google.cloud import bigquery

# Instantiates a Client for Bigquery Service
bigquery_client = bigquery.Client()

Now, i wanted to write a Python script(.py file) which will do both the tasks instead of using Terminal.

How can it be done ? Kindly advise ? Thanks

Upvotes: 1

Views: 921

Answers (1)

DYZ
DYZ

Reputation: 57085

You can change the environment within a Python script. The environment is stored in the dictionary os.environ:

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/Users/mac/Desktop/Bigquery-Key.json"

Upvotes: 2

Related Questions