首页 > 解决方案 > OsX 的 Rstudio 中缺少 rJava 图像

问题描述

当我尝试在 OsX High Sierra 上的 RStudio 中加载库(“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 '/Users/ognjenmilicevic/RPlay/Methylation_Mayo_Vesna_Garovic/libs/rJava/libs/rJava.so':
  dlopen(/Users/ognjenmilicevic/RPlay/Methylation_Mayo_Vesna_Garovic/libs/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
  Referenced from: /Users/ognjenmilicevic/RPlay/Methylation_Mayo_Vesna_Garovic/libs/rJava/libs/rJava.so
  Reason: image not found

我尝试重新配置 Java,但错误仍然存​​在:

$ R CMD javareconf
Java interpreter : /usr/bin/java
Java version     : 10.0.1
Java home path   : /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar

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/jdk-10.0.1.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/include/darwin  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -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/jdk-10.0.1.jdk/Contents/Home/lib/server -ljvm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
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.

删除并重新安装软件包没有帮助。我尝试使用以下方法指向我的版本:

dyn.load('/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/lib/server/libjvm.dylib')

错误仍然存​​在。当作为命令运行时,它一直在 R 中工作。路径“/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib”来自哪里,如何将其更改为指向我的安装?

标签: rstudiorjava

解决方案


看起来您的安装有点混乱,或者rJava.

您始终可以rJava通过调用以下命令检查使用了哪个版本的 Java(在构建时):

> otool -L /Library/Frameworks/R.framework/Resources/library/rJava/libs/rJava.so
/Library/Frameworks/R.framework/Resources/library/rJava/libs/rJava.so:
    rJava.so (compatibility version 0.0.0, current version 0.0.0)
    /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib (compatibility version 1.0.0, current version 1.0.0)
    /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libR.dylib (compatibility version 3.6.0, current version 3.6.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1259.11.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

在你的情况下,你必须打电话

> otool -L /Users/ognjenmilicevic/RPlay/Methylation_Mayo_Vesna_Garovic/libs/rJava/libs/rJava.so

确保您已安装此 Java 版本:jdk-11.0.1.jdk. 如果您没有它,并且您想安装rJava当前版本的JDK- 例如:jdk-10.0.1.jdk,请按照此处的步骤操作:http ://www.owsiak.org/r-java-11-and-making-sure-you -can-load-rjava/

另外,请记住,在 macOS 中,默认的 Java 是最新的。这意味着RStudio将选择具有最高编号的版本 - 启用的版本。

您可以通过调用禁用给定版本的 Java

> cd /Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents
> mv Info.plist Info.plist~

上面的命令将使这个 Java 版本对 macOS “不可见”。

一旦您按照这些步骤(如链接文章中所述),您将能够从以下两者运行 Java:R 和 RStudio

> R

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rJava)
> .jinit()
> J("java.lang.System","getProperty","java.version")
[1] "11.0.3"
>

在此处输入图像描述


推荐阅读