R语言问题集锦

「Debug R」MacOS中rJava加载失败

2019-05-24  本文已影响46人  xuzhougeng

在Mac中安装好rJava后用 library(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/zgxu/Library/Rlib/rJava/libs/rJava.so':
  dlopen(/Users/zgxu/Library/Rlib/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/zgxu/Library/Rlib/rJava/libs/rJava.so
  Reason: image not found

根据我的推断,应该是环境变量JAVA_HOME的设置问题,于是通过检索,找到MacOS的Java实际路径/Library/Java/JavaVirtualMachines/JDK版本号/Contents/Home

所以我在~/.bashrc中增加了下面的

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/jre"

不再报错,开心。

上一篇下一篇

猜你喜欢

热点阅读