Search code examples
macospython-2.7clangopenmprpy2

Installing rpy2 on python 2.7 on macOS


I have python version 2.7.10 on macOS High Sierra and would like to install rpy2.

When I do sudo pip install rpy2

I get the error message:

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-build-Nwbha3/rpy2/

I have already upgraded setuptools (version 39.0.1).

I also downloaded the older version rpy2-2.7.0.tar.gz and tried installing it with sudo pip install rpy2-2.7.0.tar.gz. I then get the following error message:

clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
error: command 'cc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-O0cu4E-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-haDUA3-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-O0cu4E-build/

If somebody has the answer to my installation problem, it would be greatly appreciate it. Many thanks in advance!


Solution

  • The clang that ships with Mac does not support openmp which is what the -fopenmp flag is for. You'll likely need a version of clang that supports openmp.

    One possible solution would be to get the full llvm/clang build with openmp support. With homebrew you can do:

    brew install llvm    # clang/llvm
    brew install libomp  # OpenMP support
    

    And then try installing rpy2 again with newly installed version of clang.

    As an example, the current version is 6.0.0 so you would run

    CC=/usr/local/Cellar/llvm/6.0.0/bin/clang pip install rpy2