像一群人一样,我无法在RStudio中加载rJava - 在直接使用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
当我检查options("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
任何想法都会受到赞赏。
答案 0 :(得分:5)
我有类似的问题。最快的解决方案是手动加载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
。
答案 1 :(得分:1)
在Mac OX系统上重新安装java时,需要关闭所有r会话,然后使用系统命令行R CMD javareconf
答案 2 :(得分:0)
这需要我花费大量时间在mac OS中解决。
你可以试试这些:
R 3.4, rJava, macOS and even more mess ;)和此R, Java, rJava and macOS adventures
你可以在那里找到非常详细的说明。但请注意,有些人会按照这些说明面临系统特定问题:(
并且很难找到能够解决人们发现的所有问题的解决方案。
答案 3 :(得分:0)
对我来说,这条指令做到了:
如果您在尝试卸载并重新安装 Java 之前已经安装了 Java:
Windows 10 - 卸载程序