Cannot pip install rpy2 with latest R 3.4.0 (unsupported option '-fopenmp') on macOS

Issue #403 resolved
Clemens Brunner
created an issue

Installing rpy2 with the latest R 3.4.0 doesn't work on macOS. Apparently, R 3.4.0 was built using the '-fopenmp' flag with Clang 4.0.0, which is not supplied by Apple. Therefore, pip install rpy2 gives the following error:

    gcc -bundle -undefined dynamic_lookup -L/usr/local/anaconda/lib -L/usr/local/anaconda/lib -arch x86_64 build/temp.macosx-10.7-x86_64-3.6/./rpy/rinterface/_rinterface.o -L/usr/local/lib -L/usr/local/anaconda/lib -Lbuild/temp.macosx-10.7-x86_64-3.6 -L/usr/local/lib -lpcre -llzma -lbz2 -lz -licucore -lm -liconv -lr_utils -o build/lib.macosx-10.7-x86_64-3.6/rpy2/rinterface/ -fopenmp -F/Library/Frameworks/R.framework/.. -framework R
    clang: error: unsupported option '-fopenmp'
    error: command 'gcc' failed with exit status 1

Everything worked fine with R 3.3.3 (which was built with the system Clang).

Comments (118)

  1. Laurent Gautier

    Disclaimer: I don't have a dev OS X to test anything of this.

    Could this is be because R was compiled with gcc rather than clang ? Did you try with gcc (easiest might be to install it with homebrew)

  2. Laurent Gautier
    • changed status to open

    An alternative might be to work out precompiled binaries for OS X but since I currently do not have access to a dev environment with OS X for rpy2, and since this would likely open up additional complexity because of R versions, this would have to be contributed by someone.

  3. Clemens Brunner reporter

    @pkulkarni2110 as a workaround, you can continue to use R 3.3.3, which is the last version that works with rpy2. @Laurent Gautier I have a Mac, but setting up the tools that were used to build R 3.4.0 could be a PITA. Unless I could just use the versions in Homebrew - I saw that they have LLVM version 4.0.0, but gcc is at 7.1.0 (and gcc@6 is 6.3.0 and not 6.1.0), so not sure it will be that easy. IMO it was quite an unfortunate decision from the R devs not to use Apple provided tools.

  4. Clemens Brunner reporter

    @Laurent Gautier either way this situation is not ideal, because it might entail having two pip packages for macOS depending on which R version you want to connect to. I don't think that this is even possible. Unless of course rpy2 built with the newer compiler versions also works with older R versions built with Apple-provided stuff.

  5. pkulkarni2110

    I installed R ver 3.3. I installed XQuartz as it was mentioned in the R webpage to install in macOs. I cannot certainly say it was helped to resolve the issue in anyway. Yes it is not ideal situation but it did work for temporarily.

  6. Clemens Brunner reporter

    Installing XQuartz is not necessary. I agree that this is just a temporary workaround - all future versions of R will be built with the newer tools, so eventually rpy2 will need to support it. MacOS High Sierra will likely ship with these updated build tools, so when rpy2 is built for this platform everything should hopefully work with R 3.4.0 and higher. Still, the question remains how rpy2 will handle older macOS versions. I guess we'd have to try if building with the newer tools produces a package that works both with R 3.4.0 as well as older versions such as R 3.3.3. I can try to build it and see if it works when I have time.

  7. Laurent Gautier

    @Clemens Brunner : I might be missing something here. How is this a support issue with rpy2 rather than an inconvenience of the R binaries on OS X ? rpy2 is getting its compilation flags (-fopenmp, presumably among other flags, here) from the installed R binary.

  8. Clemens Brunner reporter

    Because rpy2 doesn't work with R 3.4.0 or later, since requires a clang version that supports the -fopenmp flag. Since rpy2 gets the compiler flags from the R binary, is it possible to disable the -fopenmp flag if it is found? This would probably solve the issue.

  9. Clemens Brunner reporter

    Besides that, it is quite a bit of work to install the latest clang. I just tried it using Homebrew - and rpy2 installs fine! Here's what I did:

    brew install --with-toolchain llvm
    export PATH="/usr/local/opt/llvm/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"; pip3 install rpy2

    I'm not sure if we should expect rpy2 users on macOS to run through these steps (especially since the first step takes a long time because it compiles llvm from source).

  10. Laurent Gautier

    It might install, and may be even run, but that not something I'd like to hardcode in (which would mean support it). We can leave your workaround, someone may want to contribute "wheel" binaries for OS X, but otherwise building from source will require the toolchain the R binary itself was built with.

  11. Clemens Brunner reporter

    You mean the workaround using R < 3.4.0? Since I have the toolchain already setup I could provide a binary wheel for macOS. Two issues I see here:

    1. The binary wheel works only with R >= 3.4.0 - can pip determine which R version the user has installed and decide which wheel to install?
    2. I don't know how to create a binary wheel, maybe you could give me some instructions.
  12. Clemens Brunner reporter

    OK, but so far the source wheels worked and you only need a binary wheel for macOS using R >= 3.4.0 and all sorts of Python versions. The minimum should be Python 3.6 here, so this would be only one wheel if patch version levels are not important (i.e. Python 3.6 works like 3.6.1, similarly for R 3.4.0 and 3.4.1 etc). Let me know if you need anything from me to create this binary wheel.

  13. David Grunderson

    To piggyback of this issue, I have also been experiencing this same bug, though I am using R version 3.4 and Python version 2.7. would there be any way to get rpy2 to function with Python 2.7? I have been experiencing a great number of difficulties in trying to install rpy2, despite having tried pip, easy_install, and downloading the source tar. Despite my R being up to date and located in the PATH environmental variable, I have consistently received the same error:

      clang: error: unsupported option '-fopenmp'
        error: command 'cc' failed with exit status 1

    I have tried numerous approaches to solving this, including downloading XCode for OSX, as well as importing architecture flags, such as:

    env ARCHFLAGS="-arch i386 -arch x86_64" pip install rpy2

    I have also tried to installing the latest GCC compilers, but that made no change on the error yielded during rp2's installation process. Then I tried implementing commands suggested by Clemens Brunner above, and found that they worked perfectly, but only for Python 3.4. Is there any other approach you would recommend in order for rpy2 to function with Python 2.7?

  14. Clemens Brunner reporter

    Another much simpler option is to remove the -fopenmp linker flag (at least on macOS, I have no idea if this flag works on Windows). I just added the following lines to after line 272:

    if "-fopenmp" in unknown:  # remove linker argument

    Lo and behold, everything works just fine with the latest R 3.4.1 (all tests pass). But of course I'm not using OpenMP.

  15. Dan Li

    I have followed @ Clemens Brunner and run the following three command. I installed llvm, set the environment in .bash_profile, and source it to activate the change. I installed rpy2 in python3. But I still got the same error.

    brew install --with-toolchain llvm
    export PATH="/usr/local/opt/llvm/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"; pip3 install rpy2

    I also tried to install OpenMPI in But it didn't help.

    It is so annoying. Can anyone give me some help?

  16. Clemens Brunner reporter

    @Dan Li try uninstalling and then re-installing by ignoring the cache:

    pip3 uninstall rpy2
    export PATH="/usr/local/opt/llvm/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
    pip3 install --no-cache-dir rpy2
  17. Dan Li

    Sorry, I still get the error.

        clang: error: unsupported option '-fopenmp'
        error: command 'gcc' failed with exit status 1
    Command "/Users/danli/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/gn/y3k01wts6yvg9z_m0zlqnllm0000gn/T/pip-build-viF4iB/rpy2/';f=getattr(tokenize, 'open', open)(__file__);'\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/gn/y3k01wts6yvg9z_m0zlqnllm0000gn/T/pip-XQWVG4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/gn/y3k01wts6yvg9z_m0zlqnllm0000gn/T/pip-build-viF4iB/rpy2/
  18. Dan Li

    Hi, Clemens Brunner. Here is the info.

    DanmatoMacBook-Pro:paper danli$ which clang
    DanmatoMacBook-Pro:paper danli$ clang --version
    clang version 4.0.1 (tags/RELEASE_401/final)
    Target: x86_64-apple-darwin16.7.0
    Thread model: posix
    InstalledDir: /usr/local/opt/llvm/bin
  19. Clemens Brunner reporter

    Somehow the build process still uses gcc instead of clang. I don't know why this worked for me out of the box, but you could either symlink gcc to clang (and g++ to clang++), or explicitly tell pip to use clang (this is actually where I'll stop, because I have no experience with distutils, but you could try to go from here or here). Alternatively, you could try the simpler option I mentioned above (add the two lines to and install via python3 install). Lastly, if you install the package directly without pip, you could also try python3 install --compiler=clang.

  20. Clemens Brunner reporter

    BTW, although Apple has updated clang in High Sierra, they have disabled the fopenmp option. So unfortunately this means that installing rpy2 on a Mac via pip still doesn't work out of the box (if the latest R version is installed).

  21. Sanjiv Das

    I have tried everything to install rpy2 on High Sierra running R3.4.1 and Python3.6 (anaconda). Btw, downgrading to R3.3.3 also does not work. I get the following error:

    unable to execute 'x86_64-apple-darwin13.4.0-ar': No such file or directory error: command 'x86_64-apple-darwin13.4.0-ar' failed with exit status 1

    I think its related to the same issue in this thread, but if not, and there is hope for a fix, please let me know. I ran into this problem only after upgrading OSX to High Sierra.

  22. zach
    xcode-select --install
    xcode-select: error: command line tools are already installed, use "Software Update" to install updates

    But brew install --with-toolchain llvm gives

    ==> cmake -G Unix Makefiles /private/tmp/llvm-20171023-25020-f0tmy8/llvm-5.0.0.s
    Last 15 lines from /Users/me/Library/Logs/Homebrew/llvm/01.cmake:
    CMake Warning at tools/xcode-toolchain/CMakeLists.txt:60 (message):
      Failed to detect the version of an installed copy of Xcode, falling back to
      highest supported version.  Set XCODE_VERSION to override.
    CMake Error at tools/xcode-toolchain/CMakeLists.txt:80 (message):
      Could not identify toolchain dir
    -- Configuring incomplete, errors occurred!
    See also "/tmp/llvm-20171023-25020-7zds3a/CMakeFiles/CMakeOutput.log".
    See also "/tmp/llvm-20171023-25020-7zds3a/CMakeFiles/CMakeError.log".
    These open issues may also help:
    faust. v2.1.0 (new formula)
    gdb: Automatic code signing
    cling 0.4 (new formula)
    infer 0.13.0
    pypy crashes with dyld: lazy symbol binding failed: Symbol not found: _clock_gettime
  23. zach

    To clarify, this thread began with references to fopenmp but I'm not seeing this in any of my output. My current pip install rpy2 attempt ends with

        x86_64-apple-darwin13.4.0-ar rc build/temp.macosx-10.9-x86_64-3.6/libr_utils.a build/temp.macosx-10.9-x86_64-3.6/./rpy/rinterface/r_utils.o
        unable to execute 'x86_64-apple-darwin13.4.0-ar': No such file or directory
        error: command 'x86_64-apple-darwin13.4.0-ar' failed with exit status 1
  24. zach
    $ brew config
    HEAD: 270b752f5d9d218bfbed6fe85b6974fa653fb25f
    Last commit: 6 days ago
    Core tap ORIGIN:
    Core tap HEAD: b7d1e926e9f2e3e950866b7e82ad1fbe34f1fb12
    Core tap last commit: 23 hours ago
    HOMEBREW_PREFIX: /usr/local
    HOMEBREW_REPOSITORY: /usr/local/Homebrew
    HOMEBREW_CELLAR: /usr/local/Cellar
    CPU: quad-core 64-bit broadwell
    Homebrew Ruby: 2.3.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.3.3/bin/ruby
    Clang: 9.0 build 900
    Git: 2.13.5 => /Library/Developer/CommandLineTools/usr/bin/git
    Perl: /usr/bin/perl
    Python: /Users/me/Applications/anaconda3/bin/python => /Users/me/Applications/anaconda3/bin/python3.6
    Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    Java: N/A
    macOS: 10.12.6-x86_64
    Xcode: 9.0.1
    X11: N/A
  25. Clemens Brunner reporter

    Looks good too. I have no idea why brew install --with-toolchain llvm fails on your machine. However, you could try to use the system clang and just remove the -fopenmp flag as I've mentioned here.

  26. zach

    OK. python install (after editing, which doesn't really seem to make a difference) gives

    $ python install
    R version 3.4.2 (2017-09-28) -- "Short Summer"
    /Library/Frameworks/R.framework/Resources/bin/R CMD config --ldflags
    /Library/Frameworks/R.framework/Resources/bin/R CMD config --cppflags
    Traceback (most recent call last):
      File "", line 357, in <module>
        ri_ext = getRinterface_ext()
      File "", line 272, in getRinterface_ext
        if "-fopenmp" in unknown:  # remove linker argument
    UnboundLocalError: local variable 'unknown' referenced before assignment
    Zachs-MBP:rpy2-2.9.0 me$ python install
    R version 3.4.2 (2017-09-28) -- "Short Summer"
    /Library/Frameworks/R.framework/Resources/bin/R CMD config --ldflags
    /Library/Frameworks/R.framework/Resources/bin/R CMD config --cppflags
        Compilation parameters for rpy2's C components:
            include_dirs    = ['/Library/Frameworks/R.framework/Resources/include']
            library_dirs    = ['/usr/local/lib']
            libraries       = ['pcre', 'lzma', 'bz2', 'z', 'icucore', 'm', 'iconv']
            extra_link_args = ['-fopenmp', '-F/Library/Frameworks/R.framework/..', '-framework', 'R']
    running install
    running bdist_egg
    running egg_info
    writing rpy2.egg-info/PKG-INFO
    writing dependency_links to rpy2.egg-info/dependency_links.txt
    writing requirements to rpy2.egg-info/requires.txt
    writing top-level names to rpy2.egg-info/top_level.txt
    R version 3.4.2 (2017-09-28) -- "Short Summer"
    reading manifest file 'rpy2.egg-info/SOURCES.txt'
    reading manifest template ''
    warning: no previously-included files matching '*patch*' found anywhere in distribution
    warning: no previously-included files matching '*diff*' found anywhere in distribution
    warning: no previously-included files matching '.hg' found anywhere in distribution
    warning: no files found matching 'MANIFEST'
    warning: no files found matching 'README'
    no previously-included directories found matching 'dist'
    warning: no files found matching 'doc/source/rpy2_logo.png'
    writing manifest file 'rpy2.egg-info/SOURCES.txt'
    installing library code to build/bdist.macosx-10.9-x86_64/egg
    running build_clib
    building 'r_utils' library
    x86_64-apple-darwin13.4.0-ar rc build/temp.macosx-10.9-x86_64-3.6/libr_utils.a build/temp.macosx-10.9-x86_64-3.6/./rpy/rinterface/r_utils.o
    unable to execute 'x86_64-apple-darwin13.4.0-ar': No such file or directory
    error: command 'x86_64-apple-darwin13.4.0-ar' failed with exit status 1
  27. Clemens Brunner reporter

    Weird. I tried it on my Mac and the procedure works (with Homebrew llvm and with the system clang and modified Let's see if the Homebrew devs can help.

  28. Sanjiv Das

    I was finally able to install as follows (Mac OS High Sierra + R 3.4.0).

    (a) Install the latest version of the Java SDK: jdk-8u151-nb-8_2-macosx-x64.dmg

    (b) Then use conda as follows: conda install rpy2

    Hope this helps everyone.

  29. Clemens Brunner reporter

    You don't need to install Java SDK, this has nothing to do with this issue. Also, conda install rpy2 has always worked, it's pip install rpy2 which causes trouble.

  30. Sanjiv Das

    Thanks Clemens, I was also not sure why I needed to upgrade JDK, but it came up when I used conda. There may be some interaction in my set up. Also conda install rpy2 does not always work on Mac environments (I have tried several), but seems to always work on all my Ubuntu setups. Not sure why, but I am relieved, and happy to have my Python and R systems talking happily to each other again on my main Macbook Pro. Appreciate all your help with this on this forum.

  31. Tomás Díaz

    I was having the same issue and followed these instructions but installation (pip install rpy2) failed with:

        ld: in '/usr/local/opt/llvm/lib/libunwind.dylib', file was built for x86_64 which is not the architecture being linked (i386): /usr/local/opt/llvm/lib/libunwind.dylib for architecture i386
        clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
        error: command '/usr/local/opt/llvm/bin/clang' failed with exit status 1

    I ran it again with : env ARCHFLAGS="-arch x86_64" pip install rpy2

    and then it worked.

  32. Yuriy Gorishniy

    Hi! I have faced the problem with openmp on Sierra and have solved it.
    1. Setting the environment variable CC in .bash_profile or aliasing gcc to gcc-7 (installed by brew) doesn't work
    2. The solution proposed by @jzweig works perfectly, namely:

    env CC=/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 pip install rpy2
  33. Clemens Brunner reporter

    Interesting to see that almost everyone needs to do something different in order to install rpy2. Bottom line is that rpy2 currently cannot be installed on Macs out of the box via pip. A binary wheel would solve all these issues. I'm still willing to contribute a Mac binary, @Laurent Gautier let me know when you are ready.

  34. Laurent Gautier

    @Clemens Brunner Sorry for the late follow-up.

    The fact that everyone appear to require something different is making me think that one binary might not work for all.

    What about writing rules for all cases reported so far into a Python script as a first step ? Patterns will likely emerge in the process, and with this a better understanding of how to address the issue in the most general way possible.

  35. Laurent Gautier

    @Clemens Brunner : my experience with Windows builds for rpy2 is that the build script should have about everything needed to: - build without manual intervention / setup by default - test requirements and report missing ones in an intelligible way to a user trying to install

    Without this the "should work" turns into a stream of posts on StackOverflow, issue reports, or even personal emails that take away too valuable time as there is suddenly an influx of users without the knowledge to setup a dev environment, and a wider gap to fill to compile in their own environment in order to troubleshoot (check the number of issues in the tracker or on OS about compiling rpy2 on Windows). In that case, leaving it to "no official support" is the most optimal alternative.

    Anyone with a PR to improve the build script on OS X ?

  36. freakwill

    gcc is ok, I ever tried it successfully. But If I only want to use llvm (in brew). How do I fix the problem. After reading the long conversation, I have no idea yet.

  37. Laurent Gautier

    @freakwill do you mean compile to LLVM's intermediate representation or use clang to compile R. The later is reported to be the way the official R binaries are built (with gfortran need - link to R's own doc found earlier in this thread:

    The resolution to the problem raised by this thread would be:

    • install gfortran as the R doc ask it

    • use gcc instead of clang

    With respect to rpy2, and a user-friendly resolution, this should translate into setup code that help handle to the switch and if possible checks are informative reports about what is missing an options at the top level. I do not have OS X to do rpy2 development, and was hoping that the OS X community would step up (I appreciate the offer to build binaries, but this is not a viable solution without having code to let anyone build the binaries easily first).

  38. Valeria Parreira

    Hi Clemens, thank you for your quick response. Yes it is related to Python 2.7. Please not that I am not a bioinformatician. I am not sure if you need this info, but I saw that you asked before:

    $ brew config HOMEBREW_VERSION: 1.5.10 ORIGIN:

    HEAD: 04efbadb9ef155c5921a03bf5f5d9052cd378c21

    Last commit: 3 days ago Core tap ORIGIN:

    Core tap HEAD: f344780cad6dd0fd1eb8e1de486c0921e5b7a5c9

    Core tap last commit: 9 hours ago HOMEBREW_PREFIX: /usr/local HOMEBREW_RUBY_WARNINGS: -W0

    CPU: quad-core 64-bit haswell

    Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby Clang: 9.0 build 900

    Git: 2.14.3 => /Applications/

    Curl: 7.54.0 => /usr/bin/curl Perl: /usr/bin/perl

    Python: /usr/local/bin/python => /usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/bin/python2.7

    Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby

    Java: N/A macOS: 10.13.3-x86_64

    Xcode: 9.2

    CLT: N/A #

    X11: 2.7.11 => /opt/X11

  39. Clemens Brunner reporter

    Do you need to use Python 2? If possible, please switch to Python 3, then you should be able to make it work. Note that Homebrew recently made Python 3 the default Python. That is, if you brew install python you get Python 3. You might need to brew uninstall python followed by brew install python.

  40. Clemens Brunner reporter

    @Laurent Gautier the only user-friendly way here is to distribute binaries on PyPI. You can't expect Mac users to install tools like gfortran or gcc. Therefore, only devs who build the binaries should be required to do that. If I understand you correctly, you want to integrate this stuff into, right? I'm not that familiar with the PyPI packaging process, so if we added code to could we create Mac binaries that just work (i.e. don't require compilation at all)?

  41. Valeria Parreira

    Unfortunately, I do need use Python 2.7.

    You are right I do have both versions: brew list: cc gettext isl libmpc mpfr pcre python3 readline xz gdbm gmp jpeg libpng openssl python r sqlite

    I have used many suggestions from this chat: pip install rpy2, env CC=/usr/local/Cellar/gcc/7.2.0/bin/gcc-7 pip install rpy2 env ARCHFLAGS="-arch x86_64" pip install rpy2

    Always get: Collecting rpy2 Using cached rpy2-2.9.2.tar.gz Complete output from command python egg_info: rpy2 is no longer supporting Python < 3. Consider using an older rpy2 release when using an older Python release.


    Command "python egg_info" failed with error code 1 in /private/var/folders/cc/jmx5qpzx58n4hk0jdnskt_cr0000gn/T/pip-build-HTSame/rpy2/

    Do you think that uninstall Python 3 will help? Thanks

  42. Clemens Brunner reporter

    Well, the error message is clear: rpy2 no longer supports Python 2! You can try to install an older version of rpy2 with pip, e.g. pip install rpy2==2.8.6. I'm not sure which version still works with Python 2, so you might need to try different versions.

  43. Valeria Parreira

    Yes. I just did not know which and how to try older versions. It seems now that I have another problem: $ pip install 'rpy2<2.9.0' --user -bash: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip: No such file or directory

    and the same with your suggestion: $ pip install rpy2==2.8.6 -bash: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip: No such file or directory

    I have no idea...any suggestion?

  44. Laurent Gautier

    @Clemens Brunner

    The only user-friendly way here is to distribute binaries on PyPI. You can't expect Mac users to install tools like gfortran or gcc. Therefore, only devs who build the binaries should be required to do that. If I understand you correctly, you want to integrate this stuff into, right? I'm not that familiar with the PyPI packaging process, so if we added code to could we create Mac binaries that just work (i.e. don't require compilation at all)?

    What I mean is that building on Mac should only be a matter of running the install script, eventually setting an environment variable like CC to specify the C compiler, and inform the user if a dependency is missing (up to the user to install it).

    Now this is largely influenced by the experience maintaining Windows binary builds in the beginning of the project. Building rpy2 was a complex process with manual steps and configuration tweaks, and when binaries stopped being officially maintained this created confusions, email traffic, and issues opened on the tracker, among users that are not familiar with compiling software, or who are familiar with it but are also used to simpler compiling processes.

    Having a simple build process, and informative messages about missing dependencies to the extent possible, will ensure that I can start having contributed binaries (as I currently do not have an OS X for rpy2 development) knowing that:

    • should the contributor of binaries move on it will be relatively easy to find someone else to help

    • should more frequent binaries (e.g., from the dev branch) or binaries including patches not yet in the main repos be needed by users it will not be excessively difficult for the user to either find someone to help or figure out how to compile

    A relatively recent answer on Stackoverflow suggests that with homebrew the process is about as simple as I hope it could be:

    If someone can confirm this, I did be happy to discuss how we could have OS X binaries on Pypi soon.

  45. Clemens Brunner reporter

    Yes, the steps mentioned in the SO answer work for me. The question is whether linking to libopenmp from Homebrew could be a problem for systems that don't have Homebrew. However, I guess most things don't use OpenMP in R, so almost everything should just work.

  46. Laurent Gautier

    @Clemens Brunner : Got it. This is not a good solution then (if we are requiring users to install homebrew to use the binaries, we might has well require them to install homebrew and install from source).

    On the other hand, I am understanding that this is the way things are currently with R on OS X: code using openmp will not work unless the library is present:

    I don't remember that rpy2 is using openmp. How do you trigger the error ?

  47. Clemens Brunner reporter

    import rpy2.robjects triggers the following error message if libomp is not installed (e.g. via Homebrew):

    ImportError: dlopen(/usr/local/lib/python3.6/site-packages/rpy2/rinterface/, 2): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
      Referenced from: /usr/local/lib/python3.6/site-packages/rpy2/rinterface/
      Reason: image not found
  48. Clemens Brunner reporter

    I use the official R package. Actually, it's a framework build, which means that all libraries are contained in /Library/Frameworks/R.framework/Resources/lib. Among others, libomp.dylib is located inside that folder. I guess this lib path should be specified when rpy2 is built (I always thought that it asks R where all required libs are located, but I might be wrong). It might be possible that what I suggested at the beginning might work, because I'm not using libomp from Homebrew at all. I'll check.

  49. Laurent Gautier

    OK. There might be a reasonable path forward then.

    At the top-level we could specify two possibilities for OS X:

    a. rpy2 will be used with official R binary or any other compatible framework build, and in that case a pre-compiled rpy2 can be made available as a wheel. In that case we need to work out how to link to matching openmp at run time (may be at build time is required as well ?). I am not very familiar with framework builds in general, so I'll need your help to both have:

    • python install that is able to build against the official R binary relatively easily (code to detect and report clearly to the user what is missing will be needed once we have what we believe to be one of the simplest ways to build rpy2 against the official R binary )

    • Eventual additional dynamic setup at run time when importing rpy2.rinterface (or calling rpy2.rinterface._rinterface.initr())

    b. rpy2 will be used with an other R binary, and in that case the user will be expected to compiled rpy2 from source. The current is already allowing it.

  50. Clemens Brunner reporter

    Yes, this sounds like a good plan. The steps I described above seem to link to the libs contained in the R framework already. I can successfully install rpy2 and also use it.

  51. Laurent Gautier

    Do you mean these steps:

    brew install --with-toolchain llvm
    export PATH="/usr/local/opt/llvm/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
    pip3 install rpy2


    I can successfully install rpy2 and also use it.

    Does it work without additional settings ? Can you still use rpy2 when the directory /usr/local/opt/llvm is absent (as I am guessing that it added by homebrew) ?

  52. Clemens Brunner reporter

    Yes, but this works:

    export LDFLAGS=-L/Library/Frameworks/R.framework/Resources/lib
    export PATH=/usr/local/opt/llvm/bin:$PATH
    pip3 install rpy2 --no-cache

    I can then brew uninstall llvm and importing rpy2.robjects still works.

  53. Laurent Gautier


    To summarize what I am understanding:

    • the headers for openmp are in the llvm install (done with homebrew)
    • the headers are required to compile rpy2 (odd, but may be because of the presence of openmp with the R binaries
    • once rpy2 is compiled the openmp library shipping with R for OS X can be used

    If the above is correct we may run into issues around mismatching openmp version numbers between the one from homebrew and the one bundled with R for OS X, but this is a place to start.

    Does building a wheel work ?

    python bdist_wheel
  54. Clemens Brunner reporter

    Yes, I think your understanding is correct. In the (unlikely?) event that mixing different versions of the header and the lib, we could even try to install the same libomp version with Homebrew that is shipped with the R binary. For now, I have successfully managed to build a binary wheel!

  55. Laurent Gautier

    Good. If you make the wheel available for rpy2-2.9.3 available to me (attachment here, if possible, otherwise link on Dropbox / Google Drive / similar) I can push it to pypi and we can see how it appears to be working for all. I can monitor the number downloads for the wheel to check whether OS X users try to install it, and we(*) will follow the issues reported or messages of support.

    (*: you are implicitly signing up to be receiving all praises, and share the issues I am unable to solve as I currently do not have access to an OS X I can use for rpy2 development)

  56. Clemens Brunner reporter

    Build instructions for macOS binary wheel


    In the root folder of the rpy2 source, type:

    brew install llvm python
    export LDFLAGS=-L/Library/Frameworks/R.framework/Resources/lib
    export PATH=/usr/local/opt/llvm/bin:$PATH
    python3 bdist_wheel

    The wheel is contained in the dist folder.

  57. Laurent Gautier


    There are 57 downloads of the wheel from pypi with zero complain so far.

    Closing the issue for now. This might remain a bit manual for the next release (manual process where I ask a binary build), but we are getting there.

  58. Justus Adam

    So I had a very similar issue and I tried reinstalling rpy2. After that didn't work I also tried installing the wheel directly. But I still get this error message

    Traceback (most recent call last):
      File "plotting/", line 6, in <module>
        import rpy2.robjects.lib.ggplot2 as ggplot2
      File "/usr/local/lib/python3.6/site-packages/rpy2/robjects/", line 16, in <module>
        import rpy2.rinterface as rinterface
      File "/usr/local/lib/python3.6/site-packages/rpy2/rinterface/", line 50, in <module>
        from rpy2.rinterface._rinterface import (baseenv,
    ImportError: dlopen(/usr/local/lib/python3.6/site-packages/rpy2/rinterface/, 2): Library not loaded: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libomp.dylib
      Referenced from: /usr/local/lib/python3.6/site-packages/rpy2/rinterface/
      Reason: image not found
  59. Gökcen Eraslan

    I compiled rpy2 on os x using homebrew llvm, compiles fine. But in runtime, I get this error related to openmp:

    OMP: Error #15: Initializing libomp.dylib, but found libomp.dylib already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see

    Any ideas?

    Here is what I did:

    brew install llvm

    export PATH="/usr/local/opt/llvm/bin:$PATH"

    export LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

    export CC=clang

    pip3 install rpy2

    Error is raised when I run PCA from scikit-learn package in a notebook where I also use rpy2 ipython magic.

  60. Clemens Brunner reporter

    Is there a specific reason why you are not using the binary wheel provided by pip? Furthermore, could you provide a minimal example so that we can reproduce the issue?

  61. Laurent Gautier

    As the wheel builds are getting available, and popular, we will see new categories of issue reports coming from OS X users:

    • no build for their version of OS X
    • no build for their version of Python (Python 3.7 is around the corner)
    • no build version for their version of R (for that one, I guess we should have the information embedded in the wheel's description - I have not looked at what are the options to achieve this)

    Also, I am getting ready to release rpy2-2.9.4 and ideally I'd coordinate the release of the source package on pypi after the wheels for OS X are tested (and I have a copy to upload them at the same as the source).

  62. Gökcen Eraslan

    Isn't it feasible to run python -m rpy2.tests on different mac OS versions with different python3 combinations using CI on bitbucket? Or does it exist already? I'm not so familiar with rpy2 development.

  63. Laurent Gautier

    @Clemens Brunner I have added the tag RELEASE_2_9_4 in branch version_2.9.x, and create issue #470 to track the relase of rpy2-2.9.4. Let me know if it is working.

    Note that R-3.5 will see a segfault at the end of the unit tests (see issues #465 and #469). This is caused by changes in R's own object handling and fixing this might take me a bit of effort. I'd like to get rpy2-2.9.4 soon, so I can focus on rpy2-3.0.0 (as fixes for the issues just mentioned might require API-breaking changes in rpy2). Thanks.

  64. Log in to comment