编程语言
首页 > 编程语言> > rJava加载错误

rJava加载错误

作者:互联网

就像一群人一样,我无法让rJava加载到RStudio中 – 同样的问题也会在直接使用R GUI时重现.

这是错误:

> require(rJava)
Loading required package: rJava
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so
  Reason: image not found

我尝试了很多方面,包括从命令行重新配置:

sudo R CMD javareconf -n

Java interpreter : /usr/bin/java
Java version     : 1.8.0_144
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
Non-system Java on macOS

trying to compile and link a JNI program 
detected JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/../include/darwin  -I/usr/local/include   -fPIC  -Wall -g -O2  -c conftest.c -o conftest.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -L/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre
Java library path: $(JAVA_HOME)/lib/server
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/darwin
JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm

当我检查选项(“java.home”)时,它被设置为NULL,因此我将其设置为以下内容:

> options("java.home"="/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre")

我还重新安装了Java SE Development Kit 8,然后重新安装了rJava.

无论如何,我继续得到同样的错误.

这是我的会话信息:

> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] colorspace_1.3-2 scales_0.5.0     compiler_3.4.1   lazyeval_0.2.0  
 [5] plyr_1.8.4       tools_3.4.1      gtable_0.2.0     tibble_1.3.4    
 [9] Rcpp_0.12.12     ggplot2_2.2.1    grid_3.4.1       rlang_0.1.2     
[13] munsell_0.4.3   

任何想法将不胜感激.

解决方法:

我有一个类似的问题.最快的解决方案是手动加载dylib.

dyn.load('/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/server/libjvm.dylib')
require(rJava)

如果上述解决方案有效,则通过将此命令添加到终端来存在长期解决方案.

sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib

找到此解决方案here.您不再需要每次手动加载dylib.

标签:java,r,rstudio,rjava
来源: https://codeday.me/bug/20190823/1698986.html