0

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.

xyxc
  • 133
  • 1
  • 1
  • 7
  • Possible duplicate of [How to keep Environment Variables when Using SUDO](http://stackoverflow.com/questions/8633461/how-to-keep-environment-variables-when-using-sudo) – xyxc Feb 20 '17 at 11:11

1 Answers1

0

sudo does not keep the user's environment variables. Maybe this can help:

How to keep Environment Variables when Using SUDO

Community
  • 1
  • 1
Christian König
  • 3,437
  • 16
  • 28