Skip to main content
 首页 » 编程设计

python之错误 : Tried to guess R's HOME but no command (R) in the PATH on centos

2024年10月24日12lori

我正在使用 R 2.7.2 和 python 2.6.6,并在 centos 6.7 上下载了 rpy2-2.7.6。我正在尝试使用多种方式在 centos 上安装 ryp2。

  1. python setup.py build --r-home=/usr/lib64/R/lib install
  2. pip install ryp2

获取常见错误:

Error: Tried to guess R's HOME but no command (R) in the PATH " .  

除此之外,我还在 .bashrc 中添加了 PATH 和 LD_LIBRARY_PATH,其中包含 R_home 和 R bin 路径。

仍然出现同样的错误。请帮我解决这个问题。

请您参考如下方法:

以下内容适用于仍在运行 Python 2.6 的 RHEL6。为了让 rpy2 安装脚本找到 R,我们需要从 Python 2.7 复制一些代码到 rpy2 的安装文件中。
运行后

pip install rpy2 

正如您所描述的那样失败了,输出告诉我们在哪里寻找下载的代码(例如/tmp/pip-build-meuser/rpy2/)

访问该文件夹并编辑 setup.py 在第一个“def”行之前添加以下代码:

import subprocess 
 
if "check_output" not in dir( subprocess ): # duck punch it in! 
    def f(*popenargs, **kwargs): 
        if 'stdout' in kwargs: 
            raise ValueError('stdout argument not allowed, it will be overridden.') 
        process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) 
        output, unused_err = process.communicate() 
        retcode = process.poll() 
        if retcode: 
            cmd = kwargs.get("args") 
            if cmd is None: 
                cmd = popenargs[0] 
            raise subprocess.CalledProcessError(retcode, cmd) 
        return output 
    subprocess.check_output = f 

保存文件。现在再次尝试您的 pip install 行;它应该工作。

供引用,该来源来自 https://hg.python.org/cpython/file/d37f963394aa/Lib/subprocess.py#l544 解决方案来自类似的问题,subprocess.check_output() doesn't seem to exist (Python 2.6.5)

如果您碰巧在没有 root 权限的服务器上运行,您可能会改用安装命令

pip install --upgrade -v --user rpy2 

将最新的 rpy2 安装到您的本地(用户)帐户中。其他一切都一样。