2

I’m trying to use rpy2 to call into R from Python. This used to work for me a while back, but I’ve just re-installed Anaconda and upgraded to Python3.5 and R 3.1.3 (still on OS X 10.7). Now when I run:

from rpy2 import robjects as ro

I get the rpath error:

ImportError: dlopen(/Users/User1/anaconda/lib/python3.5/site-packages/rpy2/rinterface/_rinterface.cpython-35m-darwin.so, 2): 
Library not loaded: @rpath/R/lib/libR.dylib
Referenced from: /Users/User1/anaconda/lib/python3.5/site-packages/rpy2/rinterface/_rinterface.cpython-35m-darwin.so
Reason: image not found

This is from inside Eclipse (Kepler) with the python environment built using Anaconda/conda. The R installation was done using the standard CRAN install (picking the latest version that would install on OS X 10.7, which is the 3.1.3), which put it here:

/Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libR.dylib

Looking at:

otool -L _rinterface.cpython-35m-darwin.so

shows the path the rpy2 interface binary is looking for:

_rinterface.cpython-35m-darwin.so:

@rpath/R/lib/libR.dylib (compatibility version 3.2.0, current version 3.2.2)

/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)

@rpath/./libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)

/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 46.1.0)

/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

/Users/aaronmeurer/anaconda/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

which shows the rpath call, which clearly doesn’t find the libR.dylib at the above installed location.

I’ve trawled other related posts and tried using install_name_tool to modify the @rpath/R/lib/libR.dylib to a fixed path to the libR.dylib, but no joy, I get an error message about _rinterface.cpython-35m-darwin.so being a malformed object:

install_name_tool -change @rpath/R/lib/libR.dylib /Library/Frameworks/R.framework/Versions/3.1/Resources/lib/libR.dylib _rinterface.cpython-35m-darwin.so
install_name_tool: object: _rinterface.cpython-35m-darwin.so malformed object (unknown load command 16)

Any other suggestions?

  • How was rpy2 installed ? (`pip install rpy2` or through anaconda ?) – lgautier Dec 22 '15 at 19:22
  • (note: the latest rpy2, 2.7.x series at the time of writing, is not tested with R < 3.2.x) – lgautier Dec 22 '15 at 19:25
  • thanks for replying Laurent – recondite_information Dec 22 '15 at 20:39
  • conda install -c https://conda.anaconda.org/r rpy2 – recondite_information Dec 22 '15 at 20:39
  • and pip install rpy2 – recondite_information Dec 22 '15 at 20:40
  • Is there a recommended earlier rpy2 version to use with R 3.1? – recondite_information Dec 22 '15 at 20:41
  • rpy2-2.5.x would be OK with that version of R (http://rpy.sourceforge.net/rpy2/doc-2.5/html/overview.html#requirements)... but Python 3.5 will almost certainly not work (rpy2-2.7.4 fixed a critical issue with Python 3.5). Why use Python 3.5 and drag an older R ? Just upgrade R. – lgautier Dec 22 '15 at 20:52
  • Thanks Laurent. I've upgraded to El Capitan (OSX 10.11.2) and re-installed Anaconda and R fully, so now on R 3.2.2. I've tried the pip install rpy2 which gives me a 2.7.5 version, but still end up with the same rpath error (after setting the R_HOME env variable). I'm wondering whether a conda install would give a better result - given that I've built everything else (Python3.5, R3.2.2) inside Anaconda. On the conda site, there is only a rpy2 2.7.0, so out of the box the conda install just grabs that. Do you know how I can get conda install to pick up the 2.7.4 (or 2.7.5)? – recondite_information Dec 25 '15 at 14:04
  • I'd suggest the opposite (try without conda) because I have seen several reports of issues associated with conda in the past. However, I am not using conda myself so I am unable to tell to which extent this was caused by exotic configurations on the user side. – lgautier Dec 26 '15 at 03:04
  • I don't have a system with OS X on which I could try out, but someone got it working, it seems: https://gist.github.com/nickgravish/7ab136fc3bcbbac8316b – lgautier Dec 30 '15 at 03:17
  • I'm trying somethign similar do you have any insight? http://stackoverflow.com/questions/42126077/use-rpy2-with-packages-installed-in-r-conda-environment – O.rka Feb 09 '17 at 20:36

0 Answers0