rJava installation fails on macOS 10.14

回眸只為那壹抹淺笑 提交于 2019-12-08 02:38:00

问题


After upgrading to MacOS Mojave (10.14.1), I'm no longer able to install rJava for R version 3.5.1 with Java version "1.8.0_102" installed.

I tried the previous solution for MacOS 10.11 but it still did not work, giving this error:

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-9.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

回答1:


Posting the solution I found in case it helps others -- I don't quite understand why this work or if it's the right way so looking for better alternatives!

This issue lead to this Apple forum where it's stated

For legacy software that looks for the macOS headers in the base system under /usr/include, please install the package file located at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg

To do this, open terminal and run these commands

cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg

then follow prompts to install the package.

After this, in the terminal, configure rJava and install as in the previous answer

sudo R CMD javareconf

R -e "install.packages('rJava')"

and it should install without problem.




回答2:


I ran into the exact problem. I solved it by:

  1. Install the latest version of Java (dmg file)

  2. Install rJava in Studio: install.packages("rJava")

  3. In the terminal: sudo mv jdk-12.0.1.jdk jdk-11.0.1.jdk

Otherwise the following error will appear in Rstudio:

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
  1. In Rstudio: library(rJava)

  2. rJava should have been loaded without issues.




回答3:


After installing JDK 11.04 LTS I rain into the same error in R Studio on Mojave

R was expecting Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk

Despite running sudo R CMD javareconf the error still persisted

Therefore I browsed to /Library/Java/JavaVirtualMachines/ in finder and renamed the folder "jdk-11.0.4.jdk" to "jdk-11.0.1.jdk"

Restarted R and both library(rJava) and library(xlsx) now work.

Hope this helps someone




回答4:


I ran into same issue, when i was trying to install "rJava" in my macOs (Mojave version).

Below steps i executed to resolve issue.

R version : 3.6.1

issue : configure: error: one or more Java tools are missing. *** JDK is incomplete! Please make sure you have a complete JDK. JRE is not sufficient.

solution : execute below command in your terminal

  1. $ /usr/libexec/java_home -V
    Matching Java Virtual Machines (1):
        1.8.0_162, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk(your Java version)/Contents/Home
  1. $ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home

  2. $ export PATH=$JAVA_HOME/bin:$PATH

  3. $ R CMD javareconf

  4. $ R --quiet -e 'install.packages("rJava", type="source", repos="http://cran.us.r-project.org")'



来源:https://stackoverflow.com/questions/53502439/rjava-installation-fails-on-macos-10-14

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!