【问题标题】:How to use R and python in a Kaggle Notebook?如何在 Kaggle Notebook 中使用 R 和 python?
【发布时间】:2020-08-17 12:44:06
【问题描述】:

我想在 Kaggle 内核中同时使用 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 用户找到了 solution,但尚未提供在 Kaggle 内核中的 Python 中调用 R 的解决方案。

【问题讨论】:

    标签: python r rpy2 kaggle


    【解决方案1】:

    可以注意到 Kaggle 内核在 anaconda 环境后面使用。例如,

    /opt/conda/bin/python3.7
    

    此外,必须在此 conda 环境中安装 R。因此,我们可以使用subprocess 库来运行following 脚本来安装R

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

    以及对应的rpy2

    !pip install rpy2
    

    我在 Kaggle 上提供了一个 notebook 并提供了完整的解释。我会很感激你的cmets。

    【讨论】:

      猜你喜欢
      • 2019-09-05
      • 2021-05-03
      • 1970-01-01
      • 2021-04-25
      • 2019-10-30
      • 2019-11-24
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多