rjava和java在Mac OS Mojave问题上与r有关的问题

时间:2019-01-07 16:07:29

标签: r rjava

我最近更新到了最新的R版本和Mojave。我不能再让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.5/Resources/library/rJava/libs/rJava.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib
  Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so
  Reason: image not found
Error: package ‘rJava’ could not be loaded
输入到终端...
 /usr/libexec/java_home -V

Matching Java Virtual Machines (2):
    10.0.1, x86_64: "Java SE 10.0.1"    /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
    1.8.0_171, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

我跑步时

 sudo 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
System Java on macOS

trying to compile and link a JNI program 
detected JNI cpp flags    : -I/System/Library/Frameworks/JavaVM.framework/Headers
detected JNI linker flags : -framework JavaVM
x86_64-apple-darwin13.4.0-clang -I/anaconda3/lib/R/include -DNDEBUG -I/System/Library/Frameworks/JavaVM.framework/Headers  -D_FORTIFY_SOURCE=2 -mmacosx-version-min=10.9 -I/anaconda3/include   -fPIC  -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -I/anaconda3/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix  -c conftest.c -o conftest.o
conftest.c:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
make: *** [conftest.o] Error 1
Unable to compile a JNI program, ignoring this though as you may not want to compile anything here
.. this is an Anaconda Distribution and conda-forge customization whereby env activation causes us
.. to call R CMD javareconf in order to dynamically detect a JDK that may be in that env. The fact
.. that we prohibit setting LD_LIBRARY_PATH is also somewhat responsible for us needing to do this
.. because ${R_HOME}/etc/ldpaths is the normal way that R dynamically finds shared libraries. This
.. is what would, in upstream R, set LD_LIBRARY_PATH. AD cannot set this as it causes all sorts of
.. issues with DT_RUNPATH / DT_RPATH on various distributions.


JAVA_HOME        : /Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
Java library path: 
JNI cpp flags    : -I/System/Library/Frameworks/JavaVM.framework/Headers
JNI linker flags : -framework JavaVM
Updating Java configuration in /anaconda3/lib/R
Done.

有人可以告诉我我该怎么做吗?我确信这已经重复了很多次,而且很明显,但是我无法弄清楚还是正确地做到了。

2 个答案:

答案 0 :(得分:0)

在Mac OS版本,Java版本和rJava版本之间跳转可能会很困难。

在这里查看您可能需要采取的相当全面的步骤列表:

http://www.owsiak.org/r-3-4-rjava-macos-and-even-more-mess/

可能需要从源代码重新编译rJava才能使其在您的环境中正常工作。

答案 1 :(得分:0)

https://github.com/rstudio/rstudio/issues/2750起重新发布最快,最有效的邮件

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