当前位置: 首页>>技术教程>>正文


错误:刚才无法加载已安装的软件包

, , , ,

问题描述

当我尝试在Eclipse中运行R控制台时,出现此错误:

....Please make sure that R package 'rj' (1.1 or compatible) is installed...

所以我试着在R控制台中安装它,如下所示:

install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")

并得到此错误:

 ** testing if installed package can be loaded
 Error : .onLoad failed in loadNamespace() for 'rj.gd', details:
 call: dyn.load(file, DLLpath = DLLpath, ...)
 error: unable to load shared object '/home/alex/R/x86_64-pc-linux-gnu-library/2.15/rj.gd/libs/rj.gd.so':
 libjvm.so: cannot open shared object file: No such file or directory
 Error: loading failed
 Execution halted
 ERROR: loading failed

我发现在使用以下命令安装rJava时:install.packages("rJava")会收到类似的错误:

** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/home/alex/R/x86_64-pc-linux-gnu-library/2.15/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed

当我运行sudo R CMD javareconf时,我得到了这个输出:

Java interpreter : /usr/bin/java
Java version     : 1.7.0
Java home path   : /usr/lib/jvm/java-7-oracle/jre
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
NOTE: Your JVM has a bogus java.library.path system property!
Trying a heuristic via sun.boot.library.path to find jvm library...
Java library path: $(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/lib/amd64/server
JNI linker flags : -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/lib/amd64/server -ljvm
JNI cpp flags    : -I$(JAVA_HOME)/../include -I$(JAVA_HOME)/../include/linux

Updating Java configuration in /etc/R
Done.

顺便说一句,我的配置是:

Ubuntu 11.10 64bit
Eclipse 3.7
Oracle-1.7-jdk
R version 2.15.1 

最佳解决思路

对于Linux(Ubuntu)用户:如果安装了oracle-java (7/8)。它将在此位置/usr/lib/jvmsudo访问是必需的。

使用以下条目创建文件/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

(取决于你的java版本,用java-7-oracle替换java-8-oracle)

然后:

sudo ldconfig

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

要么

另一种方法是使用从命令R CMD javareconf -e获得的Java库路径的值导出LD_LIBRARY_PATH并运行install.packages

次佳解决思路

我有类似的问题,并能够通过运行来解决它

R CMD javareconf -e

输出R CMD javareconf -e

Java interpreter : /export/apps/jdk/JDK-1_6_0_27/jre/bin/java
Java version     : 1.6.0_27
Java home path   : /export/apps/jdk/JDK-1_6_0_27
Java compiler    : /export/apps/jdk/JDK-1_6_0_27/bin/javac
Java headers gen.: /export/apps/jdk/JDK-1_6_0_27/bin/javah
Java archive tool: /export/apps/jdk/JDK-1_6_0_27/bin/jar
Java library path: /export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server:/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64:/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
JNI linker flags : -L/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server -L/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64 -L/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm
JNI cpp flags    : -I/export/apps/jdk/JDK-1_6_0_27/include -I/export/apps/jdk/JDK-1_6_0_27/include/linux

The following Java variables have been exported:
JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
Running: /bin/bash

LD_LIBRARY_PATH设置为与JAVA_LD_LIBRARY_PATH相同的值,如上面的输出所示。我能够安装rj。

export LD_LIBRARY_PATH=/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64/server:/export/apps/jdk/JDK-1_6_0_27/jre/lib/amd64:/export/apps/jdk/JDK-1_6_0_27/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

运行R然后安装rj

install.packages(c("rj", "rj.gd"), repos="http://download.walware.de/rj-1.1")

第三种解决思路

我找到了解决方案:

export LD_LIBRARY_PATH=/usr/lib/jvm/java-7-oracle/lib/amd64:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server

然后

sudo R CMD javareconf

注意:需要根据Java安装更新路径(java-7-oracle)。

第四种思路

我做了以下工作,它对我有用:

export LD_LIBRARY_PATH=$JAVA_LD_LIBRARY_PATH
sudo R CMD javareconf

我不得不重新启动R。

第五种思路

多年以后,我在找到R报告的错误之后,在我未能成功安装了一个需要转移到Oracle Java的软件包之后,我最终找到了这个问题。

我所要解决的只是:

$ sudo R CMD javareconf

第六种思路

或者只是在R中设置库?

我刚刚在R中运行了这个命令:

Sys.setenv(JAVA_HOME='/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server')

(将“/usr /lib /jvm /java-7-openjdk-amd64 /jre /lib /amd64 /server”替换为可以找到运行“sudo R CMD javareconf”的Java库路径)

可能不是最优雅的解决方案 – 但它对我有用!

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/6406.html,未经允许,请勿转载。