import os
os.system("export UBUNTU_MENUPROXY=0")
但是it doesn't work! why? 还是求助 stackoverflow,看到如下内容
export is a command that you give directly to the shell (e.g. bash), to tell it to add or modify one of its environment variables. You can't change your shell's environment from a child process (such as Python), it's just not possible.
Here's what's happening with you try os.system('export MY_DATA="my_export"')...
/bin/bash process, command `python yourscript.py` forks python subprocess
|_
/usr/bin/python process, command `os.system()` forks /bin/sh subprocess
|_
/bin/sh process, command `export ...` changes local environment
When the bottom-most /bin/sh subprocess finishes running your export ... command, then it's discarded, along with the environment that you have just changed.
大牛们说了,这段的线程树是这样的
/bin/bash -> /usr/bin/python -> /bin/sh
export 是在/bin/sh中执行的,执行完成后就退出这个子线程了,export了解的话就知道export是export到当前线程,对父线程不可见,于是在/usr/bin/python中当然起不到作用?
正确的设置方法是? 很简单: