The easiest way to install a python package is to use easy_install (or pip), so to install rpy2, type:
To test that it is properly installed, type:
from rpy2 import robjects; robjects.r("version")
If this code works, you should be able to import an existing R package. Yet, you may get this error:
Error in sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) :
7 arguments passed to .Internal(sub) which requires 8
line 22, in RObjectMixin
__show = rpy2.rinterface.baseenv.get("show")
LookupError: 'show' not found
It took me a while to understand that this kind of error comes from the fact that rpy2 was compiled using a given R version, and that the current R version has changed (or is simply different). If you installed rpy2 while you were using R.2.10 and then you install R.2.11 then you will need to recompile rpy2 with the proper version.
To try out the following solution, you can use a virtual environment:
Now, get the rpy2 source:
tar xvfz rpy2-2.2.4.tar.gz
and compile it. You need to tell rpy2 what is the R version you want to link with
python setup.py build --r-home <path_to_R>/R-2.13.0/ install
rpy2 is installed with the proper R version, but you also need to use the proper version yourself:
Then, you can try again the python code above to import rpy2.
Not straightforward but this solution worked for me.
Pingback: How to Fix: RPY2 Is not working with multiple R versions Installed | Dushyanth Jyothi