使用rpy.robjects时,出现了一条消息。“无法确定r home:[winerror 2]系统找不到指定的文件。

发布于 2025-01-31 10:19:33 字数 699 浏览 1 评论 0原文

我正在使用RPY2 API在Python中实现一个简单的功能。

在VSCODE中,我设法打印一个置信区间,计算Z-Statistation调用使用PIC所示的功能创建的函数。但是在打印值之前,我会收到消息“无法确定r home:[winerror 2]系统找不到指定的文件”。同一消息出现在jupyter中,但根本不允许我打印任何内容,当调用rpy2函数时,它会获得错误的“转换'rpy2py'未针对类型'< class'class'rpy2.rinterface.sexpcluse.sexplusion'&gt定义的错误“ rpy2py”。 ’'”。

还只是导入软件包本身“导入rpy22.Robjects”会重新检索相同的消息。仅导入rpy2什么都不会出现。

我试图将rscript.exe和r.exe路径添加到系统变量中,但它们不起作用,但它们都不起作用(不确定我是否正确地做到了),试图重新安装R,无效。

关于如何解决这个问题的任何线索?

所使用的函数的图像,并且在vscode中输出 与以前相同功能的输出,但在jupyter中

I'm implementing a simple function in python with the rpy2 API.

In VScode I manage to print a confidence interval, calculating Z-statistic calling the function created with the robjects as seen in the pic. But before the printed value I get the message "Unable to determine R home: [WinError 2] The system could not find the specified file". The same message appears in Jupyter but doesn't allow me to print anything at all, when calling a rpy2 function it get the error "Conversion 'rpy2py' not defined for objects of type '<class 'rpy2.rinterface.SexpClosure'>'".

Also just importing the package itself "import rpy2.robjects" retrives the same message. Import rpy2 alone doesn't show up anything.

I tried to add Rscript.exe and R.exe path to system variables but didn't work, neither of them (not sure if I did it properly), tried to reinstall R, didn't work.

Any clue on how to solve this?

Image of the function being used and it's output in VSCode
The output for the same function as before but in jupyter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我太投入 2025-02-07 10:19:33

错误的原因是Windows R已更改其注册表结构,并使当前rpy2's r安装路径检测过时。我已经推了a pr 解决这个问题,但是与此同时,您的解决方案是您的解决方案是SET R_HOME环境变量。

这是您可以做的事情:

import os
os.environ["R_HOME"] = r"C:\Program Files\R\R-4.2.0" # change as needed
import rpy2

只要您在导入任何os.environ ...行之前,在导入任何rpy2模块之前,您就应该很好。

附带说明,您还可以设置os.environ [“ r_libs_user”]使用每个用户库路径。

The cause of the error is that Windows R has changed its registry structure and it made the current rpy2's R install path detection obsolete. I've pushed a PR to address this issue, but for the meantime your solution is to set R_HOME environmental variable.

Here is what you could do:

import os
os.environ["R_HOME"] = r"C:\Program Files\R\R-4.2.0" # change as needed
import rpy2

As long as you run the os.environ... line before importing any rpy2 module, you should be good to go.

On a side note, you can also set os.environ["R_LIBS_USER"] to use per-user library path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文