0

first off all I'm using oh-my-zsh as bash. I've added my API-Key to the .zshrc file as:

export MYKEY=xxxaldjlsdfjxxxx

Run source on the .zshrc. When I access this environment variable from the terminal with:

python3
>>> import os
>>> mykey = os.environ.get('MYKEY')
>>> print(mykey)

and this prints me the value of the key. Now I'm writing a python script with Visual Studio Code from where I want to access the key. The workspace of the project is located at /Users/myname/Documents/Projectname

If I now run the same code as in terminal:

import os
mykey = os.environ.get('MYKEY')
print(mykey)

I get a 'None' as output.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Antonio K
  • 144
  • 11
  • As far as I can tell, this is specifically a problem with the IDE, not with either Python, your shell or your operating system. – Karl Knechtel Apr 06 '23 at 09:07
  • Finally I found the solution, I've to set the environment var inside the .zprofile because the python path is also set inside this file. – Antonio K Apr 06 '23 at 11:49

0 Answers0