OsX的Rstudio中缺少rJava图像

时间:2019-10-03 10:48:04

标签: 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”从哪里来?如何更改它以指向我的安装?

1 个答案:

答案 0 :(得分:0)

看起来您的安装有点混乱,或者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-例如:RStudio,请按照此处的步骤操作:http://www.owsiak.org/r-java-11-and-making-sure-you-can-load-rjava/

此外,请记住,在macOS中,默认Java是最新的Java。这意味着> cd /Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents > mv Info.plist Info.plist~ 将选择编号最高的版本-已启用的版本。

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

> 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"
>

以上命令将使该Java版本对于macOS“不可见”。

按照步骤操作(如链接文章所述),您将能够从R和RStudio两者运行Java

db/migration/

enter image description here