无法在 Mac OS 10.11 上加载 R xlsx 软件包

2022-09-01 01:59:10

我可以加载rJava和xlsxjars包,但是当我执行library(xlsx)时,我得到了一个“无法加载JVM”。以下是我的详细信息。

操作系统版本:

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11
BuildVersion:   15A284

Java 版本:

$ java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

Java Path:

$ which java
/usr/bin/java

Java Home:

$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home

R 版本:

$ R --version
R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

我如何启动R:

$ LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio

成功加载 rJava 和 xlsxjars 包:

> library(rJava)
> library(xlsxjars)

尝试加载 xlsx 包失败:

> library(xlsx)
JavaVM: requested Java version ((null)) not available. Using Java at "" instead.
JavaVM: Failed to load JVM: /bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.
Error : .onLoad failed in loadNamespace() for 'xlsx', details:
  call: .jinit()
  error: JNI_GetCreatedJavaVMs returned -1
Error: package or namespace load failed for ‘xlsx’

R 配置:

Matts-MacBook-Pro:~ matt$ R CMD javareconf
Java interpreter : /usr/bin/java
Java version     : 1.8.0_65
Java home path   : /Library/Java/JavaVirtualMachines/jdk1.8.0_65.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 OS X

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_65.jdk/Contents/Home/jre/../include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/../include/darwin -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -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_65.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_65.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

答案 1

不幸的是,这些符号链接技巧对我没有帮助。但是,我在stackoverflow上发现了类似的问题!(;)的地方)这个通过执行以下操作对我有用:

  1. 在终端中,输入以下内容以正确重新链接Java:

    sudo R CMD javareconf
    
  2. 回到 R(或 RStudio)中,从源代码安装 rJava 包:

    install.packages("rJava",type='source')
    

希望,这有帮助!


答案 2

我在加载openNLP,xlsx,RWeka等软件包时也遇到了问题。并收到与您相同的错误消息。但最终这个命令在OS X 10.11.3上对我有用:sudo ln -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib