在 macOS 的 python 2.7 上安装 rpy2

Installing rpy2 on python 2.7 on macOS

我在 macOS High Sierra 上有 python 版本 2.7.10,我想安装 rpy2。

当我执行 sudo pip install rpy2

我收到错误消息:

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

我已经升级了 setuptools(版本 39.0.1)。

我还下载了旧版本的 rpy2-2.7.0.tar.gz 并尝试使用 sudo pip install rpy2-2.7.0.tar.gz 安装它。然后我收到以下错误消息:

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/

如果有人能解决我的安装问题,将不胜感激。 非常感谢!

Mac 附带的 clang 不支持 openmp,而 -fopenmp 标志的用途是。您可能需要支持 openmp 的 clang 版本。

一个可能的解决方案是获得支持 openmp 的完整 llvm/clang 构建。使用自制软件,您可以:

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

然后尝试使用新安装的 clang 版本再次安装 rpy2

例如,当前版本是 6.0.0 所以你会 运行

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