我在macOS sierra(10.12.5)上运行R(版本3.4.0),并且尝试使用xlsx库,该库要求使用rJava库。

当我尝试在R控制台中使用library(rJava)加载rJava时(无论是在RStudio中还是在终端中),都会收到以下错误消息,使我难以理解:

Fehler: package or namespace load failed for ‘rJava’:
 .onLoad in loadNamespace() für 'rJava' fehlgeschlagen, Details:
  Aufruf: dyn.load(file, DLLpath = DLLpath, ...)
  Fehler: kann shared object '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/libs/rJava.so' nicht laden:
  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

在这个问题上进行了搜索,我发现了很多类似的帖子(但每次都有一些稍有不同的问题),其中this SO question是最有前途的。

由于建议的步骤需要适应我的情况,而且我是一个新手,因此我无法实现它们。我能做什么?

附加信息:

shell命令java -version返回:
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

然后,shell命令R CMD javareconf返回:
Java interpreter : /usr/bin/java
Java version     : 1.8.0_131
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_131.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_131.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_131.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_131.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_131.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
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

任何帮助将不胜感激!

最佳答案

有用!

在安装并重新安装了不同的Java版本并使用R命令install.packages("rJava")重新安装了rJava之后,我发现在R控制台(shell窗口)中加载库不再抛出错误消息。

之后,我可以通过运行以下shell命令,使用this post中的答案使其在RStudio中工作:

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

毕竟不太复杂!谢谢大家的耐心配合。

关于java - R,加载rJava错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44157869/

10-11 02:25