Cannot load rJava because cannot load a shared library
I have been struggling to load the rJava package in R.
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
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\
The thing that finally solved my problem was to explicitly add \server\
to the PATH variable.
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.
Here are the versions of R and Java that I'm using (on 64-bit 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)
System information: R version 3.0.1 (2013-05-16) Platform: x86_64-w64-mingw32/x64 (64-bit)
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')
Note that I used this particular line because I was on a 64 bit system. See website for 32-bit example.
Following up on some of Dirk's sage advice:
- 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\
.
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.
Note that the package clearly lists
SystemRequirements: java
and that the rJava site clearly states the following
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.
so I think we have a few smoking guns pointing the same way.
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.
精彩评论