Skip to main content

os.getenv("xxx") shows different result while using sudo or not to run python3

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.

Solved

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

How to keep Environment Variables when Using SUDO


Comments

Popular posts from this blog

Can't deploy apk from eclipse in ubuntu 10.10

I've been making some apps for android for quite a while but I've only been using windows 7. Due to some reasons sometimes I'm forced to program in linux so I followed the guide to configure the SDK and eclipse (http://developer.android.com/guide/developing/device.html). After that I ran "adb devices" and got this: List of devices attached ???????????? device As you can see the name is unknown but this also happens in windows so I didn't fret too much over it. Then I launched eclipse and made a very simple project to test the deployment but here two things happened: 1st- It doesn't detect the android SDK version. (http://img515.imageshack.us/img515/5611/escolha.jpg) 2nd- when I try to deploy I get the following output: [2010-10-09 23:06:45 - testeAndroid] Android Launch! [2010-10-09 23:06:45 - testeAndroid] adb is running normally. [2010-10-09 23:06:45 - testeAndroid] Performing com.examples.teste.teste activity launch [2010-10-09 23:06:45...