问题
I am using the Spyder Anaconda IDE for Python. I am writing a code in the Spyder IDE that requires few environment variables to be set ($CPATH, $LIBRARY_PATH and $LD_LIBRARY_PATH) for the Theano library.
I am starting Spyder using the command
sudo ./spyder
and it starts fine. Even though I set the environment variables in my
/root/.bashrc
file, the code still fails to accept the path and if I try printing
print os.environ["LD_LIBRARY_PATH"]
it raises a KeyError.
I tried all the above with a normal user but still it fails. How can I get Spyder IDE to be able to view files in the above paths and where can I set them inside Spyder?
回答1:
You need to tell the sudoers
file which Environmental Variables to keep when using the sudo
command.
To edit the sudoers file run.
sudo visudo
Then add the following line to the end of it.
Defaults env_keep = "LD_LIBRARY_PATH CPATH LIBRARY_PATH"
Then export
your variable.
export LD_LIBRARY_PATH="/path/to/library"
Now you should be able to run it.
More info can be found here How to keep Environment Variables when Using SUDO
来源:https://stackoverflow.com/questions/31162021/why-do-the-environment-variables-set-in-command-prompt-have-no-effect-when-i-sta