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.