加载 rJava 时出错 [英] Error while loading rJava

查看:28
本文介绍了加载 rJava 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想加载 rJava 时出现错误.JDK 已安装.(我在 CentOS 虚拟机上运行 R(cloudera demo vm cdh3u4))

I get an error when I'd like to load rJava. JDK is installed. (I run R on a CentOS VM (cloudera demo vm cdh3u4))

> library(rJava)

Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/cloudera/R/x86_64-redhat-linux-gnu-library/2.15/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory
Error: package/namespace load failed for ‘rJava’

LD_LIBRARY_PATH 设置有问题吗?如果是,我该如何解决?我需要运行 rJava 以便稍后安装 rhdfs.

Is there something wrong with LD_LIBRARY_PATH settings? If yes, how can I fix that? I need rJava running that to install rhdfs later.

更多信息(如果需要):

Some more information (if needed):

[cloudera@localhost ~]$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

推荐答案

让 rJava 工作在很大程度上取决于您的计算机配置.以下至少在 windows 平台上工作.您可以尝试检查一下,这是否对您的平台也有帮助.

Getting rJava to work depends heavily on your computers configuration. The following is working at least on a windows platform. You could try and check, if this will help you on your platform, too.

  1. 您必须使用相同的 32 位或 64 位版本:R JDK/JRE.这种混合永远不会奏效(至少对我而言).
  2. 如果您使用 64 位版本,请确保您不要将 JAVA_HOME 设置为环境变量.如果设置了这个变量,无论出于何种原因,rJava 都将无法工作.您可以检查您的 JAVA_HOME 是否设置在 R 中:

  1. You have to use the same 32bit or 64bit version for both: R and JDK/JRE. A mixture of this will never work (at least for me).
  2. If you use 64bit version make sure, that you do not set JAVA_HOME as a enviorment variable. If this variable is set, rJava will not work for whatever reason. You can check if your JAVA_HOME is set inside R with:

Sys.getenv("JAVA_HOME")

如果您需要设置 JAVA_HOME(例如,您需要它用于 maven 或其他东西),您可以在加载 rJava 之前使用以下代码在您的 R-session 中停用它:

If you need to have JAVA_HOME set (e.g. you need it for maven or something else), you could deactivate it within your R-session with the following code before loading rJava:

if (Sys.getenv("JAVA_HOME")!="")
  Sys.setenv(JAVA_HOME="")
library(rJava)

在大多数情况下,这应该可以解决问题.此外,这也将解决 在 Win7 64 位上使用 rJava 包和 R 的问题.我从 R: rJava package install failed 借用了取消设置环境变量的想法.

This should do the trick in most cases. Furthermore this will fix issue Using the rJava package on Win7 64 bit with R, too. I borrowed the idea of unsetting the enviorment variable from R: rJava package install failing.

这篇关于加载 rJava 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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