Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rJava not loading in Jupyter Notebook with R kernel

I'm trying to load library(rJava) in a Jupyter Notebook but I get the following error:

stop(gettextf("package or namespace load failed for %s", sQuote(package)), call. = FALSE, domain = NA)

I am usingh the R Kernel in Jupyter notebook.

In RStudio library(rJava) loads just fine but not in Jupyter notebook.

In a terminal when I run: java -version I get:

java version "1.8.0_111"
JAVA (TM) SE Runtime Environment (build 1.8.0_111-b14)
JAVA HotSpot(TM) 64-bit Server VM (build 25.111-b14, mixed mode)

I don't know why Jupyter Notebook is not recognizing the rJava package.

like image 700
bytebiscuit Avatar asked Dec 12 '25 02:12

bytebiscuit


1 Answers

Had the same issue. Turns out it has to do with environment variables not being present when the Jupyter Notebook server starts. Try running the following before starting the Jupyter Notebook server (on Linux):

sudo R CMD javareconf -e
export LD_LIBRARY_PATH="/usr/lib/jvm/java/jre/lib/amd64/server"

(The java in the middle of the path may be different, depending on the version you have installed. If you're using Docker, you'll need to run these commands in a startup bash script before starting the Jupyter Notebook server.)

like image 111
Attila Tanyi Avatar answered Dec 14 '25 04:12

Attila Tanyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!