“升级"后 RStudio/R 中的 rJava 加载错误;到 OSX 优胜美地 [英] rJava load error in RStudio/R after "upgrading" to OSX Yosemite

查看:27
本文介绍了“升级"后 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:

导出 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.

    在查看我已经看过的一些帖子时,我注意到我错过了另一个 SO 答案之前,建议使用以下命令行代码打开 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 工作(如上所述).但是,我想找到一种方法来解决潜在的问题,无论它是什么,这样 RStudio 就可以以通常的 Mac 方式打开,而无需命令行工具.我还担心安装旧版本的 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 优胜美地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆