Skip to content

Instantly share code, notes, and snippets.

@nickgravish
Last active June 8, 2017 11:08
Show Gist options
  • Save nickgravish/7ab136fc3bcbbac8316b to your computer and use it in GitHub Desktop.
Save nickgravish/7ab136fc3bcbbac8316b to your computer and use it in GitHub Desktop.
Rpy2 installation annoyances

Starting with R installed from the download on the CRAN website.

install rpy2 from source using

python setup.py build install     

running the unit test gives

python -m rpy2.tests
Traceback (most recent call last):
  File "/Users/nickgravish/anaconda/lib/python3.5/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/nickgravish/anaconda/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/nickgravish/anaconda/lib/python3.5/site-packages/rpy2-2.7.6-py3.5-macosx-10.5-x86_64.egg/rpy2/tests.py", line 23, in <module>
    import rpy2.tests_rpy_classic
  File "/Users/nickgravish/anaconda/lib/python3.5/site-packages/rpy2-2.7.6-py3.5-macosx-10.5-x86_64.egg/rpy2/tests_rpy_classic.py", line 3, in <module>
    import rpy2.rpy_classic as rpy
  File "/Users/nickgravish/anaconda/lib/python3.5/site-packages/rpy2-2.7.6-py3.5-macosx-10.5-x86_64.egg/rpy2/rpy_classic.py", line 5, in <module>
    import rpy2.rinterface as ri
  File "/Users/nickgravish/anaconda/lib/python3.5/site-packages/rpy2-2.7.6-py3.5-macosx-10.5-x86_64.egg/rpy2/rinterface/__init__.py", line 99, in <module>
    from rpy2.rinterface._rinterface import *
ImportError: dlopen(/Users/nickgravish/anaconda/lib/python3.5/site-packages/rpy2-2.7.6-py3.5-macosx-10.5-x86_64.egg/rpy2/rinterface/_rinterface.cpython-35m-darwin.so, 2): Library not loaded: @rpath/R/lib/libR.dylib
  Referenced from: /Users/nickgravish/anaconda/lib/python3.5/site-packages/rpy2-2.7.6-py3.5-macosx-10.5-x86_64.egg/rpy2/rinterface/_rinterface.cpython-35m-darwin.so
  Reason: image not found

From this SO http://stackoverflow.com/questions/34421680/rpy2-rpath-issue-on-os-x-10-7

install_name_tool -change @rpath/R/lib/libR.dylib /Library/Frameworks/R.framework/Versions/3.2/Resources/lib/libR.dylib _rinterface.cpython-35m-darwin.so

install_name_tool -change @rpath/R/lib/libR.dylib /Library/Frameworks/R.framework/Versions/3.2/Resources/lib/libR.dylib _rpy_device.cpython-35m-darwin.so

These two commands fixed the unit test so that everything worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment