Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

os.environ different between console and vscode

I’m trying to read system variables in my python script but for some reason it doesn’t work in vscode.

I manually set the system variable MY_ENV_VAR to test through the system gui (windows).

Now, when running os.getenv('MY_ENV_VAR') in the console, I get the expected result of 'test', but when doing the same thing in vscode, I get None.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Both console and vscode use the exact same python interpreter.

After some digging, I found out that the in the console, os.environ is slightly different compared to the one I get in vscode, one of the differences being my newly created variable.

How can I set a system variable such that I can read in from within vscode?

>Solution :

You have to restart VSCode. Environment variable changes are only reflected in processes created after the change.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading