简体   繁体   English

在 macOS Catalina 10.15.6 上安装 rJava

[英]Installing rJava on macOS Catalina 10.15.6

After many infuriating tries getting rJava to work, I've decided to do an Q&A of how I finally got it to work.在多次尝试让 rJava 工作后,我决定对我如何最终让它工作进行问答。

How do I install rJava on my MacOS system?如何在我的 MacOS 系统上安装 rJava? I use macOS Catalina 10.15.6.我使用 macOS Catalina 10.15.6。

I frequently get warning messages of the type:我经常收到以下类型的警告消息:

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错误:“rJava”的包或命名空间加载失败:“rJava”的 loadNamespace() 中的 .onLoad 失败,详细信息:调用:dyn.load(file, DLLpath = DLLpath, ...) 错误:无法加载共享对象 > '/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/Java/JavaVirtualMachines/jdk->11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib 引用自:>/Library/Frameworks/R。 framework/Versions/3.5/Resources/library/rJava/libs/rJava.so 原因:找不到图像

I've previously tried installing different JDK (Java Development Kit) from Oracle.我以前尝试过从 Oracle 安装不同的 JDK(Java 开发工具包)。 I get the warning that RStudio only wants to work together with JDK-11.0.1.我收到警告说 RStudio 只想与 JDK-11.0.1 一起工作。 To download this I would need to create an Oracle account.要下载这个,我需要创建一个 Oracle 帐户。

I've managed to solve this issue through the following steps:我已经通过以下步骤设法解决了这个问题:

  1. Remove the package rJava.删除包 rJava。 In the R console, enter:在 R 控制台中,输入:
rm.packages("rJava")
  1. Remove previous attempts to install Java on your MacOS by entering the following in the terminal :通过在终端中输入以下内容,删除以前在 MacOS 上安装 Java 的尝试:
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane 
sudo rm -fr /Library/Application\ Support/Oracle/Java

Solution to remove unwanted previous version: https://stackoverflow.com/a/50056979/11550980删除不需要的以前版本的解决方案: https : //stackoverflow.com/a/50056979/11550980

sudo rm -fr /Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdk
  1. Install OpenJDK ready for production: JDK 14.0.2安装准备用于生产的 OpenJDK:JDK 14.0.2

http://jdk.java.net/14/ http://jdk.java.net/14/

If installing manually, unpack the .tar.gz file and place the unpacked folder in: /Library/Java/JavaVirtualMachines/如果手动安装,解压 .tar.gz 文件并将解压后的文件夹放在:/Library/Java/JavaVirtualMachines/

  1. Control in the terminal:在终端控制:
java -version
  1. In the R Console:在 R 控制台中:
install.packages("rJava")
  1. You may have to reconfigure R to work with your version of Java.您可能需要重新配置 R 才能使用您的 Java 版本。 In the terminal :终端
R CMD javareconf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM