2

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.

cel
  • 30,017
  • 18
  • 97
  • 117
archana
  • 21
  • 1
  • 3

2 Answers2

2

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.

Community
  • 1
  • 1
CPBL
  • 3,783
  • 4
  • 34
  • 44
  • I have the same problem and wanted to apply your solution. However, that directory which is reported in the error line is deleted immediately after it's created. Any way to overcome this? – splinter Feb 05 '17 at 19:20
  • Sorry. I've moved on from RHEL. Can someone else help? Though Ctrl-z will interrupt/pause the pip process ... (type "fg" to resume it) – CPBL Feb 05 '17 at 22:54
0

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

sudo apt-get update

sudo apt-get install python-rpy2
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
Pierre
  • 1