0

I'm trying to use Jupyter Notebooks in VSCode. The notebook will not access my environment variables I have set on MacOS. I'm not able to find any solutions in my searches. Any help?

Edit: os.getenv returns None for my variable.

  • See this answer: https://stackoverflow.com/questions/70682613/update-env-variable-on-notebook-in-vscode tl;dr the notebook runs in a different shell than the environment where your environment variables are. So you use a tool like `dotenv` to pass the environment variables to the shell where your notebook is running. – Jonathan Rayner May 11 '23 at 14:45

1 Answers1

0

Do you get it like this?

import os
value = os.getenv('OneDrive')
print(value)

Does it work in the python script?

And please check whether you have modified it in the .env file.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
  • In a typical python script it returns as expected, in Jupyter is returns None. I have not been using a .env file, would that be the issue?! – SharkyShark Apr 07 '22 at 14:32
  • @SharkyShark Could you try to debug it in the python script? – Steven-MSFT Apr 08 '22 at 01:20
  • @SharkyShark Yes, could you find a `.env` file in your workspace folder? It can modify the system environment variable, but it will only affect anything the extension does on your behalf and actions performed by the debugger, but it will not affect tools run in the terminal. – Steven-MSFT Apr 08 '22 at 01:22