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

2022-09-01 02:15:08

当我尝试在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 

答案 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-8-oracle 替换为 java-7-oracle,具体取决于您的 java 版本)

然后:

sudo ldconfig

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

另一种方法是使用从命令中获取的Java库路径的值导出并运行LD_LIBRARY_PATHR CMD javareconf -einstall.packages


答案 2

我遇到了类似的问题,并且能够通过运行来解决它

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

设置为与上述输出中所示的相同值后。我能够安装 rj。LD_LIBRARY_PATHJAVA_LD_LIBRARY_PATH

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