Why do the environment variables set in command prompt have no effect when I start Spyder

流过昼夜 提交于 2019-12-11 09:43:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!