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?