rJava 未在 RStudio 中加載,但在 R 中工作

rJava 未在 RStudio 中加載,但在 R 中工作

我成功地透過運行安裝了 rJavaR CMD javareconf -e | tee javareconf.out

cat javareconf.out 
Java interpreter : /usr/lib/jvm/java-8-oracle/jre/bin/java
Java version     : 1.8.0_201
Java home path   : /usr/lib/jvm/java-8-oracle
Java compiler    : /usr/lib/jvm/java-8-oracle/bin/javac
Java headers gen.: /usr/lib/jvm/java-8-oracle/bin/javah
Java archive tool: /usr/lib/jvm/java-8-oracle/bin/jar

trying to compile and link a JNI program 
detected JNI cpp flags    : -I/usr/lib/jvm/java-8-oracle/include -I/usr/lib/jvm/java-8-oracle/include/linux
detected JNI linker flags : -L/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I/usr/lib/jvm/java-8-oracle/include -I/usr/lib/jvm/java-8-oracle/include/linux     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-1SEA_D/r-base-3.5.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o conftest.so conftest.o -L/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server -ljvm -L/usr/lib/R/lib -lR

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

我也在 R 中安裝了 rJava 套件 ( install.packages("rJava"))。現在,我可以使用 R 中的 rJava,但不能使用 RStudio。

我嘗試更改 LD_LIBRARY_PATH 以包含 Java lib,然後從 RStudio 中安裝 rJava,但沒有成功。export LD_LIBRARY_PATH="/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server:$LD_LIBRARY_PATH"

有趣的是,如果我打開 RStudio,sudo rstudio kill-all它的工作方式與 R 中一樣,但如果我透過點擊擴充座中的圖示開啟 RStudio,則會收到以下錯誤:

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

我嘗試重新安裝 RStudio(sudo apt purge rstudio並手動刪除主目錄中留下的 .rstudio 目錄),但這沒有幫助...

知道我能做些什麼來解決這個問題嗎?

編輯:

現在我看到問題是 R CMD javareconf 沒有更改 RStudio 的路徑,來自 RStudio 的 rJava 安裝日誌:

checking Java support in R... present:
interpreter : '/usr/lib/jvm/default-java/bin/java'
archiver    : '/usr/lib/jvm/default-java/bin/jar'
compiler    : '/usr/lib/jvm/default-java/bin/javac'
header prep.: ''
cpp flags   : '-I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux'
java libs   : '-L/usr/lib/jvm/default-java/lib/server -ljvm'
checking whether Java run-time works... ./configure: line 3766: /usr/lib/jvm/default-java/bin/java: No such file or directory
no
configure: error: Java interpreter '/usr/lib/jvm/default-java/bin/java' does not work
ERROR: configuration failed for package ‘rJava’
* removing ‘/home/kzkedzierska/R/x86_64-pc-linux-gnu-library/3.5/rJava’

知道如何改變這些嗎?相當於R CMD javareconf -e在 Rstudio 中運行?

RStudio 與 R 一起

相關內容