1. rpy2
  2. rpy2
  3. rpy2
  4. Issues


Issue #415 new

Problem installing rpy2 to work with R 3.4.0 on OSX

Vincent Liu
created an issue

I would like to use some R packages requiring R version 3.4 and above. I want to access these packages in python (3.6.1) through rpy2 (2.8).

I have R version 3.4 installed, and it is located in /Library/Frameworks/R.framework/Resources However, when I use pip3 install rpy2 to install and use the python 3.6.1 in /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6) as my interpreter, I get the error:

Traceback (most recent call last):
  File "/Users/vincentliu/PycharmProjects/magic/rpy2tester.py", line 1, in from rpy2 import robjects
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2/robjects/init.py", line 16, in
    import rpy2.rinterface as rinterface
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2/rinterface/init.py", line 92, in
    from rpy2.rinterface._rinterface import (baseenv, 
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so, 2): Library not loaded: @rpath/libiconv.2.dylib Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rpy2/rinterface/_rinterface.cpython-36m-darwin.so Reason: Incompatible library version: _rinterface.cpython-36m-darwin.so requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0

Which first seemed like a problem caused by Anaconda, and so I remove all Anaconda-related files but the problem persists.

I then uninstalled rpy2, reinstalled Anaconda and used conda install rpy2 to install, which also installs R version 3.3.2 through Anaconda. I can then change the interpreter to /anaconda/bin/python and can use rpy2 fine, but I couldn't use the R packages I care about because they need R version 3.4 and higher. Apparently, the oldest version Anaconda can install is 3.3.2, so is there any way I can use rpy2 with R version 3.4?

I can see two general solutions to this problem. One is to install rpy2 through conda and then somehow change its depending R to the 3.4 one in the system. Another solution is to resolve the error: Incompatible library version: _rinterface.cpython-36m-darwin.so requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0

After much struggling, I've found no good result with either.

Comments (4)

  1. Vincent Liu reporter

    No I don't think this is an issue with anaconda. I completely uninstalled anaconda and still kept getting the libiconv error whenever I import rpy2.robjects (importing rpy2 is fine). I used pip install rpy2 --verbose and found that a series of lib files were ignored because of an incorrect architecture issue (files built for x86 but the architecture is i386). This is strange because my system is indeed x86. So I tried export ARCHFLAGS="-arch x86_64" and reinstalled rpy2 using pip, and this resolved the problem.

    For more details, see here: https://stackoverflow.com/questions/44836123/installing-rpy2-to-work-with-r-3-4-0-on-osx

  2. Log in to comment