如何在Kaggle笔记本里面使用R和python?

问题描述 投票:0回答:1

我想在Kaggle Kernel里面同时使用R和Python语言。因此,当运行

!pip install rpy2

在Kaggle Notebook中,我得到了以下错误信息。

Error: rpy2 in API mode cannot be built without R in the PATH or R_HOME defined. Correct this or force ABI mode-only by defining the environment variable RPY2_CFFI_MODE=ABI

我发现了一个 解决办法 为R内Python的用户提供,但还没有提供在Kaggle Kernel内调用R的解决方案。

python r rpy2 kaggle
1个回答
0
投票

大家可以注意到,Kaggle Kernel背后使用的是anaconda环境。比如说

/opt/conda/bin/python3.7

另外,在这个conda环境上必须要安装R。因此,我们可以使用 subprocess 库来运行 下面 安装R的脚本

import subprocess
subprocess.run('conda install -c conda-forge r-base', shell=True)

以及相应的 rpy2 包裹

!pip install rpy2

我已经提供了一个 笔记本 在Kaggle上有一个完整的解释。请大家多多指教。

© www.soinside.com 2019 - 2024. All rights reserved.