简体   繁体   English

使用 rpy2 时 LoadLibrary 失败

[英]LoadLibrary failure with rpy2

After upgrading R and rpy2 I found a LoadLibrary failure problem with rpy2 when importing the R package stats.升级 R 和 rpy2 后,我在导入 R 包统计信息时发现 rpy2 存在 LoadLibrary 失败问题。 After running the following code:运行以下代码后:

import rpy2.robjects as robjects
from rpy2.objects.packages import importr
rstats = importr('stats')

I receive the error message我收到错误消息

RRuntimeError: Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Program Files/R/R-3.4.3/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module cannot be found.

Other modules are imported correctly, unless they import stats themselves.其他模块被正确导入,除非它们自己导入统计信息。 I have tried to reinstall R and rpy2 to no avail.我尝试重新安装 R 和 rpy2 无济于事。 A similar issue reported a problem with a path in the .Renviron file.一个类似的问题报告了 .Renviron 文件中的路径问题。 This file does not exist in my computer.这个文件在我的电脑中不存在。

My R_HOME is C:\\Program Files\\R\\R-3.4.3 and my R_USER is C:\\Users\\user.name.我的 R_HOME 是 C:\\Program Files\\R\\R-3.4.3,我的 R_USER 是 C:\\Users\\user.name。

Could you help me find what is the problem and how to solve it?您能帮我找出问题所在以及如何解决吗?

I solved the problem by adding C:\\Program Files\\R\\R-3.4.3\\bin\\x64 to the path.我通过将 C:\\Program Files\\R\\R-3.4.3\\bin\\x64 添加到路径解决了这个问题。 I think that this address was deleted from the path when I uninstalled the previous R version.我想这个地址是在我卸载以前的R版本时从路径中删除的。 And you need to install the address manually to the path after installing the new version, according to the R for Windows FAQ .安装新版本后需要手动将地址安装到路径中,参考R for Windows FAQ

For those with anaconda, I solved the problem using conda install rpy2对于那些使用 anaconda 的人,我使用conda install rpy2解决了这个问题

Also added the entry C:\\Program Files\\R\\R-4.0.2\\bin\\x64 to my user Path variable.还将条目C:\\Program Files\\R\\R-4.0.2\\bin\\x64到我的用户Path变量中。
And added the variable R_HOME with value C:\\Program Files\\R\\R-4.0.2并添加了值为C:\\Program Files\\R\\R-4.0.2的变量R_HOME
And added the variable R_USER with value C:\\ProgramData\\Anaconda3\\Lib\\site-packages\\rpy2并增加了变量R_USER值为C:\\ProgramData\\Anaconda3\\Lib\\site-packages\\rpy2

I tried many different suggestions, but this was the only solution.我尝试了许多不同的建议,但这是唯一的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM