【问题标题】:Installing RPy2 for MacOS: add the directory of the R interpreter to the PATH environment variable为 MacOS 安装 RPy2:将 R 解释器的目录添加到 PATH 环境变量中
【发布时间】:2017-04-13 08:49:54
【问题描述】:

我正在尝试在我的 MacBook Air、Yosemite 上安装 RPY2,并且我几乎按照以下website 中的说明进行操作。更具体地说,我:

  • 已安装 R 3.3.2
  • 按照 RPY2 网站的建议,使用 pip install rpy2 安装了 Rpy2
  • 使用
    echo 'R_HOME="/Library/Frameworks/R.framework/Versions/3.3/Resources"; export R_HOME' >> ~/.bashrc 将 R_HOME 变量设置为 R 主目录

但是,当我使用
from rpy2.rinterface import R_VERSION_BUILD 测试这是否适用于 Python 我得到错误:

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    from rpy2.rinterface import R_VERSION_BUILD
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/rpy2/rinterface/__init__.py", line 81, in <module>
    """)
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.

我确实需要add the directory of the R interpreter to the PATH environment variable,如果需要,我该怎么做?

【问题讨论】:

    标签: python r python-2.7 environment-variables rpy2


    【解决方案1】:

    修改~/.bashrc 后,您可能需要运行以下命令 source ~/.bashrc 否则,将 R 添加到 PATH 中,如下所示:

    export PATH=/directory/where/the/R/executable/is:${PATH}
    

    最后,我不建议使用系统的 Python(除非在一次性设置这样的容器中)。考虑使用homebrew,并使用它安装 Python 和 R。

    【讨论】:

    • 嗨@lgautier,谢谢你的建议。我会立即测试它。关于下载 Python,我是从 www.python.org 本身下载的。也可以吗?
    • 没关系,我认为(Mac 用户可以确认)。重要的部分是建议不要管系统的 Python。
    • 我已经尝试了三种方式(指向三个不同的 R 可执行文件),但仍然没有运气。即使重新启动计算机后,我也会收到相同的错误。我检查了重启后是否设置了 PATH。您可能还有其他建议吗?
    • 当您打开终端时,命令“R RHOME”是否返回路径?这基本上是 rpy2 为获取 R 的主页所做的工作。此外,如果 R 在 PATH 中,取消设置环境变量 R_HOME 可能是个好主意。
    猜你喜欢
    • 1970-01-01
    • 2010-12-27
    • 1970-01-01
    • 2019-10-21
    • 2023-03-30
    • 2020-01-03
    • 2011-10-17
    • 2014-10-23
    相关资源
    最近更新 更多