无法加载 rJava,因为无法加载共享库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2399027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot load rJava because cannot load a shared library
提问by Farrel
I have been struggling to load the rJava package in R.
我一直在努力在 R 中加载 rJava 包。
I get the following messages
我收到以下消息
> library(rJava)
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared library \
'C:/PROGRA~1/R/R-210~1.1/library/rJava/libs/rJava.dll':
LoadLibrary failure: The specified module could not be found.
Error : .onLoad failed in 'loadNamespace' for 'rJava'
Error: package/namespace load failed for 'rJava'
I have tried so many solutions that they are all bamboozeled in my head. At some point I even got
我尝试了很多解决方案,它们都在我的脑海中浮现。在某些时候我什至得到了
> R Console: Rgui.exe - System Error The
> program can't start because
> MSVCR71.dll is is missing from your
> computer. Try reinstalling the program
> to fix this problem.
I made sure everything I could think of was on the path
我确保我能想到的一切都在路上
> C:\Program Files\R\Rtools\bin;C:\Program Files\R\Rtools\perl\bin;
C:\Program Files\R\Rtools\MinGW\bin;%SystemRoot%\system32;
%SystemRoot%;%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\QuickTime\QTSystem\;
C:\Program Files\R\R-2.10.1\library\rJava\libs\;
C:\Program Files\R;C:\Program Files\Java\jre6\bin\client
What should I try next?
我接下来应该尝试什么?
I am running R version 2.10.1 (2009-12-14) and I have also tried R version 2.10.1 Patched (2010-03-03 r51210). It is on a Windows machine running windows 7 enterprise
我正在运行 R 版本 2.10.1 (2009-12-14),我也尝试过 R 版本 2.10.1 Patched (2010-03-03 r51210)。它在运行 Windows 7 Enterprise 的 Windows 机器上
采纳答案by Shane
Following up on some of Dirk's sage advice:
跟进 Dirk 的一些睿智建议:
- Your path should probably say
C:\Program Files\Java\jre6\bin\
(remove "client"). - Your path should also have
C:\Program Files\R\R-2.10.1\bin\
. You don't need that explicit reference to the rJava libs. I would also then removeC:\Program Files\R
from the path. - Lastly, confirm that Java is accessible by either going to your command prompt and typing
java -version
, or from within R by typingsystem("java -version")
. - If you install the SDK, then you will also want a system variable
JAVA_HOME
which in my case points toC:\Sun\SDK\
.
- 您的路径可能应该说
C:\Program Files\Java\jre6\bin\
(删除“客户端”)。 - 你的路径也应该有
C:\Program Files\R\R-2.10.1\bin\
. 您不需要对 rJava 库的显式引用。然后我也会C:\Program Files\R
从路径中删除。 - 最后,通过转到命令提示符并键入
java -version
或从 R 中键入 来确认 Java 是否可访问system("java -version")
。 - 如果你安装了 SDK,那么你还需要一个系统变量
JAVA_HOME
,在我的例子中它指向C:\Sun\SDK\
.
回答by Dirk Eddelbuettel
After editing your post for readability / formatting it seems that you have no Java system in your path. I don't use the OS you're trying to use this on, but on mine rJava
only works if I also install a Java Run-Time Environment or, better still, a Java SDK.
在编辑您的帖子以提高可读性/格式后,您的路径中似乎没有 Java 系统。我不使用您尝试在其上使用的操作系统,但rJava
只有在我还安装了 Java 运行时环境,或者更好的是,安装了 Java SDK 时,我的操作系统才有效。
Note that the package clearly lists
请注意,包裹中明确列出了
SystemRequirements: java
and that the rJava siteclearly states the following
并且rJava 站点清楚地说明了以下内容
Installation
First, make sure you have JDK 1.4 or higher installed (some platforms require hgher version see R Wiki). On unix systems make sure that R was configured with Java support. If not, you can re-configure R by using R CMD javareconf (you may have to prepend sudo or run it as root depending on your installation - see R-ext manual A.2.2 for details). On Windows Java is detected at run-time from the registry.
rJava can be installed as any other R package from CRAN using install.packages('rJava'). See the files section in the left menu for development versions.
JRI is only compiled if supported, i.e. if R was configured as a framework or with --enable-R-shlib.
安装
首先,确保您安装了 JDK 1.4 或更高版本(某些平台需要更高版本,请参阅 R Wiki)。在 unix 系统上,确保 R 配置了 Java 支持。如果没有,您可以使用 R CMD javareconf 重新配置 R(根据您的安装,您可能需要预先添加 sudo 或以 root 身份运行它 - 有关详细信息,请参阅 R-ext 手册 A.2.2)。在 Windows 上,在运行时从注册表中检测到 Java。
可以使用 install.packages('rJava') 将 rJava 安装为来自 CRAN 的任何其他 R 包。有关开发版本,请参阅左侧菜单中的文件部分。
JRI 仅在支持时编译,即如果 R 配置为框架或使用 --enable-R-shlib。
so I think we have a few smoking guns pointing the same way.
所以我认为我们有一些确凿的证据指向相同的方向。
回答by daniel
I had a similar error and had to do an additional fix: Setting the R path explicitly to ...bin\x64, and also being consistent in using x64 Java and R.
我有一个类似的错误,不得不做一个额外的修复:将 R 路径显式设置为 ...bin\x64,并且在使用 x64 Java 和 R 时保持一致。
回答by Hans Christian
If you have read this threat and neither of the suggestions above has worked so far, then it might be worth trying one further:
如果您已经阅读了这个威胁,但到目前为止上述建议都没有奏效,那么可能值得进一步尝试:
- Windows 7
- R version 2.12.1 (2010-12-16) 64-bit
Java(TM) SE Runtime Environment (build 1.6.0_23-b05), Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)
JAVA_HOME=C:\Program Files\Java\jre6\bin\
Path= ...;C:\Program Files\Java\jre6\bin\server\;C:\Program Files\R\R-2.12.1\bin\x64\
- Windows 7的
- R 版本 2.12.1 (2010-12-16) 64 位
Java(TM) SE 运行时环境(构建 1.6.0_23-b05)、Java HotSpot(TM) 64 位服务器 VM(构建 19.0-b09,混合模式)
JAVA_HOME=C:\Program Files\Java\jre6\bin\
Path= ...;C:\Program Files\Java\jre6\bin\server\;C:\Program Files\R\R-2.12.1\bin\x64\
The thing that finally solved my problem was to explicitly add \server\
to the PATH variable.
最终解决我的问题的是显式添加\server\
到 PATH 变量。
回答by TriumphTodd
For what it's worth, putting C:\Program Files\Java\jre6\bin\[server]
in my PATH
worked for me. It seems the rJava module could jot find jvm.dll
there.
为了它的价值,投入C:\Program Files\Java\jre6\bin\[server]
我的PATH
工作。似乎 rJava 模块可以在jvm.dll
那里找到。
Here are the versions of R and Java that I'm using (on 64-bit Windows 7).
这是我使用的 R 和 Java 版本(在 64 位 Windows 7 上)。
Java:
爪哇:
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
R:
回复:
R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-mingw32/x64 (64-bit)
回答by John Thompson
System information: R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)
系统信息:R 版本 3.0.1 (2013-05-16) 平台:x86_64-w64-mingw32/x64(64 位)
I encountered this same problem. I was able to solve the issue with one line of code into the command window obtained from this website.
我遇到了同样的问题。我能够在从该网站获得的命令窗口中输入一行代码来解决该问题。
Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre7')
Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre7')
Note that I used this particular line because I was on a 64 bit system. See website for 32-bit example.
请注意,我使用此特定行是因为我使用的是 64 位系统。有关 32 位示例,请参见网站。