Hello,
I have rstudio in jupyter (both R and Jupyter are from anaconda). Unfortunatelly I have problem with rJava package. When I try to load the package I have following error:
Loading required package: rJava
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for ‘rJava’, details:
call: dyn.load(file, DLLpath = DLLpath, …)
error: nie można załadować współdzielonego obiektu ‘/opt/anaconda3/envs/R_kernel/lib/R/library/rJava/libs/rJava.so’:
libjvm.so: nie można otworzyć pliku obiektu dzielonego: Nie ma takiego pliku ani katalogu
I try
sudo R CMD javareconf JAVA_HOME=/opt/anaconda3/envs/R_kernel/lib
but still it doesn’t help.
I check also
Sys.getenv(“JAVA_HOME”) which give me ‘/opt/anaconda3/envs/R_kernel’
Sys.getenv(“LD_LIBRARY_PATH”) or Sys.getenv(“LIBRARY_PATH”) give me empty result (only ").
What can I do also to have rJava working properly ?
Do you have a JAVA JDK installed? This is required in order for the rJava package to work.
I suggest looking at this discussion for further information:
If I run command “R CMD javareconf” I have the following output:
(base) [root@percona-1 ~]# R CMD javareconf
*** JAVA_HOME is not a valid path, ignoring
Java interpreter : /usr/bin/java
Java version : 11.0.15
Java home path : /usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.el7_9.x86_64
Java compiler : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/in clude -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/include/linux
detected JNI linker flags : -L$(JAVA_HOME)/lib/server -ljvm
gcc -std=gnu99 -I/opt/anaconda3/lib/R/include -DNDEBUG -I/usr/lib/jvm/java-1.7.0 -openjdk-1.7.0.45.x86_64/include -I/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_ 64/include/linux -I/opt/anaconda3/include -fpic -I/opt/anaconda3/include -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: Nie ma takiego pliku ani katalogu #include <jni.h>
^
compilation terminated.
make: *** [conftest.o] Błąd 1
Unable to compile a JNI program
If I don’t use sudo in the command ( so it will be something like this: " R CMD javareconf JAVA_HOME= /usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.el7_9.x86_64/bin/java" )I will have the same error like when I write “R CMD javareconf”
This looks like a pathing problem. I think you need to set JAVA_HOME’ as the user you are logged in as, while NOT running the ‘sudo’ command. Check your
“PATH” environment variable as well and compare it to when you are running R CMD javreconf using ‘sudo’.