简体   繁体   English

如何将R_HOME环境变量设置为R主目录?

[英]How to set the R_HOME environment variable to the R home directory?

I am trying to import rpy2 into python and I am getting this error: 我试图将rpy2导入到python中,我收到此错误:

RuntimeError: The R home directory could not be determined.
Try to install R <https://www.r-project.org/>,
set the R_HOME environment variable to the R home directory, or
add the directory of the R interpreter to the PATH environment variable.

I am completely lost here as I have no idea what this is telling me. 我完全迷失在这里,因为我不知道这告诉我什么。 I tried to search up how to set the environment variable and couldn't find anything detailed enough that was helpful for me. 我试图搜索如何设置环境变量,但找不到任何对我有帮助的详细信息。 I would appreciate it if the answer could be very straightforward as I am just a newbie. 如果答案可以非常简单,我会很感激,因为我只是一个新手。 I am running OSX 10.11. 我正在运行OSX 10.11。

Thank you (my first post, I apologize if I overlooked any rules in posting) 谢谢(我的第一篇文章,如果我忽略了发布中的任何规则,我道歉)

It is the other way around -- the R in your PATH should know its home: 反过来了 - 你的PATH的R应该知道它的家:

edd@don:~$ R RHOME
/usr/lib/R
edd@don:~$ 

This echos the last line recommendation -- have your R in the PATH . 这回应了最后一行推荐 - 让你的R在PATH

On another machine with both R and R-devel, I choose to address the latter under a different name. 在另一台同时具有R和R-devel的机器上,我选择以不同的名称解决后者。 Still, each knows its HOME : 每个人都知道它的HOME

edd@max:~$ /usr/local/lib/R-devel/bin/R RHOME
/usr/local/lib/R-devel/lib/R
edd@max:~$ R RHOME
/usr/lib/R
edd@max:~$ 

Setting R_HOME this way worked for me 以这种方式设置R_HOME对我有用

import os
os.environ['R_HOME'] = '/path/to/R'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM