It happened to me when I try to use os.getenv.
I have edited the "\etc\profile" file to add an env variable and ran the source command.
And I wrote some codes to test it.It worked well and I can get the env variable I set when I run python just using python3 command in the command line.
But I find it doesn't work when I using sudo python3.The os.getenv("xxx") returns None. That's the question.Why it doesn't work just because of using sudo.