We have recently upgraded our computing farm nodes from Ubuntu 10.04.4 to Ubuntu 12.04.3. We have user specific (/usr/bin) R & Pythons as well as network installed multiple versions of R(R-2.15.2, R-3.0.0), and pyhonbrew’s pythons(2.7.2,etc).We use RPY2(2.3.6) along with network installed R(R-2.15.2) and Python(2.7.2) which all are working fine until we updated Ubuntu. After the upgrade, using rpy2 throwing several different types of errors, some of them looks like:
import rpy2 from rpy2 import robjects; Error in paste0("(^|[^%])(%%)*%", spec) : not a BUILTIN function Traceback (most recent call last): File "", line 1, in File "<path_to_python>/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 18, in from rpy2.robjects.robject import RObjectMixin, RObject File "<path_to_python>/lib/python2.7/site-packages/rpy2/robjects/robject.py", line 9, in class RObjectMixin(object): File "<path_to_python>/lib/python2.7/site-packages/rpy2/robjects/robject.py", line 22, in RObjectMixin __show = rpy2.rinterface.baseenv.get("show") LookupError: 'show' not found
Or
Error in sub("[[:blank:]]*([[:alnum:]]+)", "\\1", dp) : 7 arguments passed to .Internal(sub) which requires 8
Or
Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/software/R-2.15.2/lib/R/library/stats/libs/stats.so': libRlapack.so: cannot open shared object file: No such file or directory During startup - Warning message: package ‘stats’ in options("defaultPackages") was not found
Since our original rpy2 was build aginst old Ubuntu/R/Python shared libraries, we suspected that we may need to recompile it again to fix the rpy2 issues.
Thomas Cokelaer made a nice blog post on how to do this, This blog post is kind of extension to his solution.
So, I started off with re-installing rpy2 again.
First un-install rpy2:
pip uninstall rpy2
This un-install only removing the file “<path_to_python>/lib/python2.7/site-packages/rpy2-2.3.6-py2.7.egg-info”, but not the entire rpy2 directory, so manually delete just to be sure:
rm -rf <path_to_python>/lib/python2.7/site-packages/rpy2/
Download RPY2
wget https://pypi.python.org/packages/source/r/rpy2/rpy2-2.3.6.tar.gz tar -zxvf rpy2-2.3.6.tar.gz cd rpy2-2.3.6
Set right environment variables:
#Python setup setenv PYTHONBREW_ROOT <path_to_pythonbrew> setenv PATH <path_to_pythonbrew>/pythons/Python-2.7.2/bin:${PATH} setenv PYTHONPATH <path_to_pythonbrew>/pythons/Python-2.7.2/lib
# R setup setenv PATH <path_to_r>/R-2.15.2/lib/R/bin:${PATH} setenv R_HOME <path_to_r>/R-2.15.2/lib/R setenv R_LIBS_USER <path_to_r_user_libraries>/Rlib
Now recompile rpy2 against Intended R by specifying its location:
python setup.py build --r-home <path_to_r>/R-2.15.2 install
In most scenarios this should be good enough for rpy2 to work, however if you are unlucky like me, then read on..
After some frustrating hours of googling, un-re-installing rpy2, using different versions of python & R, I decided to dig further examining the shared objects that are used by running Python and R processes:
lsof -p <r_process_id> | awk '{print $9}' | grep '\.so' lsof -p <python_process_id> | awk '{print $9}' | grep '\.so'
Then I looked at what shared objects are loaded particularly by “<path_to_r>/R-2.15.2/lib/R/bin/exec/R”:
ldd /software/R-2.15.2/lib/R/bin/exec/R linux-vdso.so.1 => (0x00007fff1dbff000) libR.so => /usr/lib/libR.so (0x00007f2661c05000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f26619e8000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2661627000) libblas.so.3gf => /usr/lib/libblas.so.3gf (0x00007f26610be000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2660dc2000) libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f2660b7f000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f2660942000) liblzma.so.5 => /usr/lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f2660720000) libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f266050f000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f26602f8000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f26600f0000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f265feeb000) libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f265fcdd000) /lib64/ld-linux-x86-64.so.2 (0x00007f2662178000) libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007f265f9c6000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f265f7af000) libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f265f588000) libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f265f351000)
As you can see from the output libR.so “libR.so => /usr/lib/libR.so (0x00007f2661c05000)” is loading from local R library instaed of my intended network R location.
This suppose to load like “libR.so => /software/R-2.15.2/lib/R/lib/libR.so (0x00007f328c64e000)”
Since, i don’t have admin privileges to touch network installed R or re-configure default SO’s, I fixed it by amending following environmental variable so that proper SOs are loaded:
setenv LD_LIBRARY_PATH /software/R-2.15.2/lib/R/lib:${LD_LIBRARY_PATH}
After again re-installing rpy2 and testing, all works as intended:
python -m 'rpy2.tests'
Hope this helps to someone in the similiar situataion..