为什么在我启动Spyder时在命令提示符下设置的环境变量无效? [英] Why do the environment variables set in command prompt have no effect when I start Spyder

查看:823
本文介绍了为什么在我启动Spyder时在命令提示符下设置的环境变量无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Spyder Anaconda IDE用于Python.我正在Spyder IDE中编写代码,该代码需要为Theano库设置几个环境变量($ CPATH,$ LIBRARY_PATH和$ LD_LIBRARY_PATH).

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.

我正在使用命令启动Spyder

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"]

它会引发KeyError.

it raises a KeyError.

我用普通用户尝试了以上所有方法,但仍然失败.如何使Spyder IDE能够查看上述路径中的文件,以及如何在Spyder中设置它们?

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?

推荐答案

使用sudo命令时,您需要告诉sudoers文件要保留哪些环境变量.

You need to tell the sudoers file which Environmental Variables to keep when using the sudo command.

要编辑sudoers文件,请运行.

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"

然后export您的变量.

export LD_LIBRARY_PATH="/path/to/library"

现在您应该可以运行它了.

Now you should be able to run it.

更多信息可以在这里找到如何在使用时保持环境变量SUDO

More info can be found here How to keep Environment Variables when Using SUDO

这篇关于为什么在我启动Spyder时在命令提示符下设置的环境变量无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆