java 加载 rJava 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13403268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:35:40  来源:igfitidea点击:

Error while loading rJava

javarcentosclouderarjava

提问by SWR

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))

当我想加载 rJava 时出现错误。安装了JDK。(我在 CentOS 虚拟机上运行 R(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'

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

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

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)

回答by Tejus Prasad

For Ubuntu, oracle-java (7/8) installed. It'll be at this location /usr/lib/jvm and sudo access is required.

对于 Ubuntu,已安装 oracle-java (7/8)。它将在此位置 /usr/lib/jvm 并且需要 sudo 访问权限。

Create the file /etc/ld.so.conf.d/java.confwith the following entries:

/etc/ld.so.conf.d/java.conf使用以下条目创建文件:

/usr/lib/jvm/java-8-oracle/jre/lib/amd64
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server

(Replace java-8-oracle with java-7-oracle or java-7-openjdk-amd64 depending on your java version)

(根据您的 Java 版本将 java-8-oracle 替换为 java-7-oracle 或 java-7-openjdk-amd64)

Then:

然后:

sudo ldconfig

Restart RStudio and then install the rJava package.

重新启动 RStudio,然后安装 rJava 包。

回答by user2161065

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

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

  1. You have to use the same32bit or 64bit version for both: R andJDK/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_HOMEas 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")
    
  1. 您必须为两者使用相同的32 位或 64 位版本:RJDK/JRE。这种混合永远不会奏效(至少对我而言)。
  2. 如果您使用 64 位版本,请确保不要将 JAVA_HOME 设置为环境变量。如果设置了这个变量,无论出于何种原因,rJava 都将无法工作。您可以使用以下命令检查您的 JAVA_HOME 是否设置在 R 中:

    Sys.getenv("JAVA_HOME")
    

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:

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

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

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.

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