I am not able to import my API key to my jupyter notebook which is on web browser, I tried importing it shows None
. What do I do?
I was excepting the API key to be printed as that is what I tried importing, but it printed None
.
5
I am 90% sure this is a question with an answer somewhere else, but here you go:
# os for accessing the env
import os
from dotenv import load_dotenv
# loading variables from .env file
load_dotenv() # pass a path if it's not a .env in the current working directory
# accessing and printing value
print(os.getenv("VARIABLE_NAME"))
this is if your jupyter is being executed locally. The browser is merely where you look at the notebook, the actual calculation/execution of python could be any place. So if you are using e.g. google collab it is running on googles computers and you need to upload it to the instance.
For debugging you can check where python is executed by printing the current working directory and it’s contents
import os
cwd=os.getcwd()
print(cwd)
print(os.listdir(cwd))
Is the path what you expect? is the content of the folder a folder on your computer?
4