Running some v basic scripts with environment variables so I don’t have to hard code things like my api key or id. My code wouldn't run and was failing on authorising so either my id and/or key didn't work. So I just printed out the variables to see where it died.

import os
user = os.getenv('USER') 
tempLocation = os.getenv('TEMP') 
Id = os.getenv('MY_ID') 
Key = os.getenv('MY_KEY')

print(user) 
print(tempLocation) 
print(Id) 
print(Key)

But I’m getting different responses depending on where the code is run. My output is below, the id and key have been altered for here but they are returning info. From WSL terminal I’m only retuning my user name:

me 
None 
None 
None

But if I use the Jupyter interactive terminal in VS Code I get:

None 
C:\Users\me\AppData\Local\Temp 
xxxxxx 
1234567890abcdefg

I'd prefer to be able to just run the script from my WSL terminal cos that's quicker for things to run in the future, but without the env getting keys/site ID it's a bit of a pain.

Sounds proper. One system may be using the WSL (Linux) subsystem and the other could be a Windows system. I don't expect the env variable to match because, different environments.
https://docs.microsoft.com/en-us/windows/wsl/basic-commands tells us we have to setup the WSL to be a specific user and well, that setup isn't known here.

Next time, open a command line (bash, etc) type env and see what's set there. Same for powershell.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.