rJava load error in RStudio/R after quot;upgradingquot; to OSX Yosemite(“升级后 RStudio/R 中的 rJava 加载错误到 OSX 优胜美地)
问题描述
我最近从 OSX Mountain Lion 升级"到了 Yosemite,从 R 3.1.3 升级到了 3.2.升级后,当我立即打开 R 或 RStudio 时,我收到一条弹出消息,说我需要安装 Java 6.此外,加载 rJava
或任何依赖于 rJava 的包(例如,xlsx
) 导致 RStudio 崩溃(当我通过直接打开 R.app
进行尝试时,R 也崩溃了).
I recently "upgraded" from OSX Mountain Lion to Yosemite and from R 3.1.3 to 3.2. Immediately after the upgrade, when I opened R or RStudio I got a pop-up message saying that I needed to install Java 6. In addition, loading rJava
or any package that depends on rJava (e.g., xlsx
) caused RStudio to crash (R also crashed when I tried this by opening R.app
directly).
在尝试了在 Stack Overflow 和其他地方找到的一些修复程序(下面有更多详细信息)之后,我正在加载 rJava
或任何依赖于 rJava
的包更长的时间会导致 R 崩溃,但会导致以下错误:
After trying a few fixes found on Stack Overflow and elsewhere (more details below), I am at a point where loading rJava
or any package that depends on rJava
no longer causes R to crash, but results in the following error:
library(rJava)
Error : .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.2/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: @rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so
Reason: image not found
Error: package or namespace load failed for ‘rJava’
但是,如果我从命令行调用 R,然后加载 rJava
或任何依赖于 rJava
的包,它似乎可以工作(或者至少我没有t 收到任何错误消息).
However, if I invoke R from the command line and then load rJava
or any package that depends on rJava
, it seems to work (or at least I don't get any error messages).
我已经尝试了许多不同的尝试修复,其中一些尝试了几次,但我不太记得我按照什么顺序做了什么(没有意识到这会是一个如此糟糕的问题,而且不是真的跟踪),但这里是它的要点:
I've tried a number of different attempted fixes, some of them a few times, and can't quite remember exactly what I did in what order (didn't realize this would be such a morass and wasn't really keeping track), but here's the gist of it:
在我的
.bash_profile
中添加了以下内容(根据 this SO answer):
Added the following to my
.bash_profile
(per this SO answer):
导出 JAVA_HOME="/usr/libexec/java_home -v 1.8"
导出 LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/server
export JAVA_HOME="/usr/libexec/java_home -v 1.8"
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/server
从命令行重新配置java如下:
Reconfigured java from the command line as follows:
sudo R CMD javareconf -n
sudo R CMD javareconf -n
检查了 options("java.home")
并发现它被设置为 NULL
.我尝试将其设置为以下(根据 this SO question):
Checked options("java.home")
and discovered this was set to NULL
. I tried setting it to the following (per this SO question):
options("java.home"="/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre")
options("java.home"="/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre")
安装了最新的 Java 开发工具包并从源代码重新安装了 rJava
(不记得我在哪里找到的).
Installed the latest Java Development Kit and reinstalled rJava
from source (can't remember where I found that one).
在尝试所有这些时,我能够加载 rJava
而不会导致 R 崩溃,但收到了上面发布的错误消息.另外,当我退出RStudio时,它似乎可以正常关闭,但随后会弹出RStudio意外退出"消息,表明程序在尝试关闭时崩溃了.
At some point while trying all of these, I was able to load rJava
without crashing R, but instead got the error message posted above. In addition, when I quit RStudio, it would seem to close normally, but then an "RStudio quit unexpectedly" message would pop up, indicating that the program had crashed while trying to close.
我终于决定安装 Java for OS X 2014-001(Java6),因为我似乎没有选择.现在,当我打开 R 或 RStudio 时,此软件需要 Java 6"弹出消息不再出现.但是,我仍然收到上面发布的 .onLoad failed in loadNamespace() for 'rJava'
错误消息.
I finally decided to install Java for OS X 2014-001 (Java 6), as I seemed to be running out of options. Now, when I opened R or RStudio the "This software needs Java 6" pop-up message no longer appeared. However, I was still getting the .onLoad failed in loadNamespace() for 'rJava'
error message posted above.
在查看我已经看过的一些帖子时,我注意到 another SO answer 我错过了之前,它建议使用以下命令行代码打开 RStudio,为 RStudio 提供正确的 java 路径:
In reviewing some of the posts I'd already looked at, I noticed another SO answer that I'd missed before, which recommended opening RStudio with the following command line code that gives RStudio the correct path to java:
LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio
LD_LIBRARY_PATH=$(/usr/libexec/java_home)/jre/lib/server: open -a RStudio
这打开了一个 RStudio 窗口,我还能够加载 rJava
和依赖它的包而不会出错.
That opened an RStudio window and I was also able to load rJava
and packages that depend on it without getting an error.
最后,我尝试从命令行运行 R(我以前没有这样做过).事实证明,在命令行中,加载 rJava
或任何依赖于 rJava
的包都可以正常工作并且不会抛出任何错误.
Lastly, I tried running R from the command line (which I hadn't done before). It turns out that on the command line, loading rJava
or any package that depends on rJava
works and does not throw any errors.
所以,如果我从命令行使用为 RStudio 提供 java 路径的代码打开 RStudio(如上所述),我现在可以让 rJava
工作.但是,我想找到一种方法来解决潜在的问题,无论它可能是什么,以便可以以通常的 Mac 方式打开 RStudio,而无需使用命令行.我还担心安装旧版本的 Java 可能会导致问题.
So, I can now get rJava
to work if I open RStudio from the command line with the code that gives RStudio the java path (as noted above). However, I'd like to find a way to fix the underlying problem, whatever it may be, so that RStudio can be opened in the usual Mac way, without needing a command line kludge. I'm also concerned that having an old version of Java installed could cause problems down the road.
有人对如何诊断和解决此问题有任何想法吗?
Does anyone have any ideas about how to diagnose and solve this issue?
推荐答案
我遇到了和你一样的问题,经历了同样的步骤.允许通过 Finder/Spotlight 启动 RStudio 的最后一步是将 libjvm.dylib 链接到/usr/local/lib:
I had the same problem and went through the same steps as you. The final step to allow starting RStudio through Finder/Spotlight was to link libjvm.dylib to /usr/local/lib:
sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
-f
标志被添加以强制覆盖现有文件/链接
-f
flag is added to force overwriting existing file/link
这篇关于“升级"后 RStudio/R 中的 rJava 加载错误到 OSX 优胜美地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“升级"后 RStudio/R 中的 rJava 加载错误到 OSX 优胜美地
基础教程推荐
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01