archana
archana

Reputation: 21

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

I am using R 2.7.2 and python 2.6.6 and downloaded rpy2-2.7.6 on centos 6.7 . I am trying to install ryp2 on centos using multiple ways .

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

getting common error:

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

Beside this I also added the PATH as well as the LD_LIBRARY_PATH in .bashrc having the R_home and R bin path.

Still getting same error. Please help me to solve this issue.

Upvotes: 2

Views: 4178

Answers (2)

Pierre
Pierre

Reputation: 1

Why use pip while you can install the package as follows:

sudo apt-get update

sudo apt-get install python-rpy2

Upvotes: 0

CPBL
CPBL

Reputation: 4030

The following worked on RHEL6, which is still running Python 2.6. In order for the rpy2 installation script to find R, we need to copy a bit of code from Python 2.7 into the setup file for rpy2.
After running

pip install rpy2

which fails as you describe, the output tells us where to look for the downloaded code (e.g. /tmp/pip-build-meuser/rpy2/ )

Visit that folder and edit setup.py Add the following code right before the first "def" line:

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

Save the file. Now try your pip install line again; it should work.

For reference, that source came from https://hg.python.org/cpython/file/d37f963394aa/Lib/subprocess.py#l544 and the solution is from a similar question, subprocess.check_output() doesn't seem to exist (Python 2.6.5)

If you happen to be running on a server without root access, you might instead be using the install command

pip install --upgrade -v --user rpy2

to install the latest rpy2 into your local (user) account. Everything else is the same.

Upvotes: 2

Related Questions