Jupyter 中的基本 rpy 失败

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

我的想法
我不知道这是 conda 问题还是 rpy 问题。

背景
我正在尝试让 rpy 在 jupyter/python 中运行。

这是我正在使用的:

  • 微软 Windows 11 专业版
  • 蟒蛇22.9.0
  • Python 3.7.16
  • R 基 3.6.1

我还安装了几个帮助程序包:

  • numpy 版本:1.23.5
  • scipy版本:1.10.0
  • opencv版本:4.6.0
  • matplotlib 版本:3.6.2

我安装了rpy2版本2.9.4

当我执行以下代码时:

import rpy2
import rpy2.situation
for row in rpy2.situation.iter_info():
    print(row)

我得到以下输出:

rpy2 version:
3.5.11
Python version:
3.9.16 (main, Jan 11 2023, 16:16:36) [MSC v.1916 64 bit (AMD64)]
Looking for R's HOME:
    Environment variable R_HOME: None
    InstallPath in the registry: C:\Program Files\R\R-4.2.2
    Environment variable R_USER: None
    Environment variable R_LIBS_USER: None
R version:
    In the PATH: R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
    Loading R library from rpy2: OK
Additional directories to load R packages from:
None
C extension compilation:
    Warning: Unable to get R compilation flags.
Directory for the R shared library:

此时,它给了我一长串以此开头的错误:

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[14], line 5
      2 import rpy2
      4 import rpy2.situation
----> 5 for row in rpy2.situation.iter_info():
      6     print(row)

以此结束:

File c:\Users\username\.conda\envs\this_env_name\lib\subprocess.py:528, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    526     retcode = process.poll()
    527     if check and retcode:
--> 528         raise CalledProcessError(retcode, process.args,
    529                                  output=stdout, stderr=stderr)
    530 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '('C:\\Program Files\\R\\R-4.2.2\\bin\\x64\\R', 'CMD', 'config', 'LIBnn')' returned non-zero exit status 1.

当我尝试运行这个时:

import rpy2.robjects

以下是产生的错误的第一位和最后一位。

R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) : 
  3 arguments passed to .Internal(gettext) which requires 2

---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
Cell In[16], line 4
      1 #
      2 import rpy2
----> 4 import rpy2.robjects


File c:\Users\username\.conda\envs\this_env_name\lib\site-packages\rpy2\rinterface.py:817, in SexpClosure.__call__(self, *args, **kwargs)
    810     res = rmemory.protect(
    811         openrlib.rlib.R_tryEval(
    812             call_r,
    813             call_context.__sexp__._cdata,
    814             error_occured)
    815     )
    816     if error_occured[0]:
--> 817         raise embedded.RRuntimeError(_rinterface._geterrmessage())
    818 return res

RRuntimeError: Error in gettext(fmt, domain = domain, trim = trim) : 
  3 arguments passed to .Internal(gettext) which requires 2

这些没有前进的方向,尽管最后一个似乎相关:

这个说使用 pip 而不是 conda,但这是毒害 conda 环境的好方法。它们可以一起被攻击,但也可以互相破坏。
如何在python中正确安装rpy2?

观察
它应该使用的 R 应该是 R-3.6 左右,而不是 R-4.2.2。

问题
如何让 rpy 在 jupyter 中运行而不破坏 conda?我只想让 python 调用 r 脚本,并让它在 python 工作区中的对象上运行,然后将一个新对象返回到 python 工作区。

python r jupyter-notebook jupyter rpy2
1个回答
0
投票

我也遇到了这个问题。查看文档(https://rpy2.github.io/doc/v3.5.x/html/overview.html#install-installation),它实际上说当前不支持在Windows上运行rpy2尽管最近报道了 3.3.x 系列中最新版本的相对成功。我想这就是问题所在?

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