rpy2是一个Python的包,允许你在Python内部调用R语言。但假如你用的是苹果电脑,那么当你通过pip install -U rpy2
安装或更新时有可能会报错执行时可能会报错,报错信息类似:
clang: error: unsupported option '-fopenmp'
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1:
/Users/XXXX/Documents/pythonEnv/py3env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/xb/wh94wqxs4h5cyrwldqmh823h0000gn/T/pip-install-tv10qqh0/rpy2/setup.py'"'"'; __file__='"'"'/private/var/folders/xb/wh94wqxs4h5cyrwldqmh823h0000gn/T/pip-install-tv10qqh0/rpy2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/xb/wh94wqxs4h5cyrwldqmh823h0000gn/T/pip-record-a5acw6zs/install-record.txt --single-version-externally-managed --compile --install-headers /Users/XXXX/Documents/pythonEnv/py3env/bin/../include/site/python3.7/rpy2 Check the logs for full command output.
我在这里找到了解决方法,如下:
- 首先确保你的苹果电脑上安装了Homebrew,
如果没有,在终端运行/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
详见Homebrew官网 - 通过Homebrew安装gcc,在终端运行
brew install gcc
若已安装请忽略此步骤 - 终端运行
env CC=/usr/local/Cellar/gcc/X.x.x/bin/gcc-X pip install rpy2
其中的X.x.x
请换成你安装的gcc版本,比如我的版本为9.2.0_3
,那么我应该运行
env CC=/usr/local/Cellar/gcc/9.2.0_3/bin/gcc-9 pip install rpy2
这样rpy2就成功安装了。