在 linux 中无法“pip3 install rpy2”

Posted

技术标签:

【中文标题】在 linux 中无法“pip3 install rpy2”【英文标题】:Failed to 'pip3 install rpy2' in linux 【发布时间】:2021-08-12 16:35:46 【问题描述】:

每个人。我尝试在 Centos6.10 中安装 rpy2,使用 Python 3.6.4 和 R 版本 3.5.2。我使用了命令“pip3 install rpy2”。我收到以下错误:

cwd: /tmp/pip-install-7bxzxlni/rpy2_0e939a480cc0488d918a202af1b64127/
Complete output (153 lines):
['cffi>=1.10.0', 'jinja2', 'pytz', 'tzlocal']
running install
running build
cffi mode: CFFI_MODE.ANY
running build_py
file _rinterface_cffi_abi.py (for module _rinterface_cffi_abi) not found
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/rpy2
...(many copy information like this "copying ./rpy2/rinterface_lib/memorymanagement.py -> build/lib.linux-x86_64-3.6/rpy2/rinterface_lib")

file _rinterface_cffi_abi.py (for module _rinterface_cffi_abi) not found
generating cffi module 'build/lib.linux-x86_64-3.6/_rinterface_cffi_abi.py'
running build_ext
generating cffi module 'build/temp.linux-x86_64-3.6/_rinterface_cffi_api.c'
creating build/temp.linux-x86_64-3.6
building '_rinterface_cffi_api' extension
creating build/temp.linux-x86_64-3.6/build
creating build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -O2 -pipe -fPIC -DRPY2_RLEN_LONG=True -DR_INTERFACE_PTRS=True -Irpy2/rinterface_lib/ -I/home/work/.jumbo/include/python3.6m -c build/temp.linux-x86_64-3.6/_rinterface_cffi_api.c -o build/temp.linux-x86_64-3.6/build/temp.linux-x86_64-3.6/_rinterface_cffi_api.o
In file included from build/temp.linux-x86_64-3.6/_rinterface_cffi_api.c:569:
rpy2/rinterface_lib/R_API.h:199: warning: function declaration isn’t a prototype
In file included from build/temp.linux-x86_64-3.6/_rinterface_cffi_api.c:570:
rpy2/rinterface_lib/R_API_eventloop.h:26: error: redefinition of typedef ‘InputHandler’
rpy2/rinterface_lib/R_API_eventloop.h:8: note: previous declaration of ‘InputHandler’ was here
error: command 'gcc' failed with exit status 1
----------------------------------------
    ERROR: Command errored out with exit status 1: /home/work/.jumbo/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-7bxzxlni/rpy2_0e939a480cc0488d918a202af1b64127/setup.py'"'"'; __file__='"'"'/tmp/pip-install-7bxzxlni/rpy2_0e939a480cc0488d918a202af1b64127/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-lx5dv6cc/install-record.txt --single-version-externally-managed --compile --install-headers /home/work/.jumbo/include/python3.6m/rpy2 Check the logs for full command output.

'''

由于“命令'gcc'失败,退出状态为1”,我安装了here中提到的所有东西。由于“退出状态为 1 的命令出错”,我参考了 here~,例如,我尝试了 'pip3 install --upgrade rpy2' 并且我还尝试首先升级我的 pip3。但是这些方法对我没有帮助。此外,我关注的是this way 和this~。第一个没有帮助,后者将在我的命令“python3 setup.py build --r-home /usr/lib64/R/ install”之后出现“错误:选项--r-home 无法识别”。

这里有一些其他信息:

    echo$PATH
    bash:echo/home/work/.jumbo/bin/core_perl:/home/work/.jumbo/bin:/home/work/.jumbo/bin/core_perl:/home/work/.jumbo/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/opt/bin:/home/opt/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/bin:/home/opt/bin:/usr/local/git/bin:/home/work/bin: No such file or directory

    echo$R_HOME
    bash: echo/usr/lib64/R: No such file or directory

    echo$LD_LIBRARY_PATH
    

请帮帮我!

【问题讨论】:

【参考方案1】:

我通过启动 R 并输入 'Sys.getenv("R_HOME")' 得到我的“R_HOME”。输出是“/usr/lib64/R”。这就是我在 /etc/profile 中通过“export R_HOME=/usr/lib64/R”创建变量“R_HOME”的原因。现在我使用'which R',我得到'/usr/bin/R',所以我将“R_HOME”变量从“/usr/lib64/R”更改为“/usr/bin/”,这解决了我的问题!哦耶!我希望我的经验可以帮助一些人。

【讨论】:

以上是关于在 linux 中无法“pip3 install rpy2”的主要内容,如果未能解决你的问题,请参考以下文章

pip3 install --upgrade pip升级安装后无法使用的解决步骤

pip3 install xxx 失败查找步骤

Mac中 pip3 install mysqlclient 报错

安装pip3 install sanic?

ubuntu下pip3 install 模块缓慢解决方案

pip3 install scrap报错