问题描述
我的总体目标是在Jupyter实验室的Azure云服务上的R Jupyter笔记本中使用sparklyr
.我用R,sparklyr和Java 8创建了一个新的conda环境(因为这是sparklyr支持的版本),如下所示:
My overall aim is to use sparklyr
within an R Jupyter notebook on my Azure cloud service of Jupyter lab. I created a new conda environment with R, sparklyr and Java 8 (since this is the version supported by sparklyr) as follows:
conda create -n r_spark r=3.6 r-essentials r-irkernel openjdk=8 r-sparklyr
source activate r_spark
R
> IRkernel::installspec(user=TRUE, name="rspark", displayname="R (Spark)")
当我在此环境中的终端会话中运行R 时,一切正常:
When I run R within a terminal session within this environment, everything works fine:
R
> system("java -version")
openjdk version "1.8.0_152-release"
OpenJDK Runtime Environment (build 1.8.0_152-release-1056-b12)
OpenJDK 64-Bit Server VM (build 25.152-b12, mixed mode)
> library(sparklyr)
> sc <- spark_connect(master="local")
* Using Spark: 2.3.3
Registered S3 method overwritten by 'openssl':
method from
print.bytes Rcpp
> spark_disconnect(sc)
NULL
>
但是,当我在笔记本中用相同的"R(Spark)"内核执行相同的操作时,它将使用Java openjdk版本11:
However, when I do the same within a notebook with the very same "R (Spark)"-kernel, it uses Java openjdk version 11:
library(sparklyr)
sc <- spark_connect(master="local")
Error in validate_java_version_line(master, version): Java version detected
but couldnt parse version from: openjdk version "11.0.4" 2019-07-16
Traceback: [...]
此外,system("java -version", intern=TRUE)
从笔记本内部返回空结果.
Furthermore system("java -version", intern=TRUE)
returns an empty result from within the notebook.
如何告诉笔记本使用其环境中的Java版本?
How can I tell the notebook to use the Java version from its environment?
推荐答案
@merv的评论使我走上了正轨:
@merv's comment put me on the right track:
在环境以下终端中的R控制台中,使用Sys.getenv("JAVA_HOME")
获取当前的JAVA_HOME
-path.
Get the current JAVA_HOME
-path with Sys.getenv("JAVA_HOME")
in the R console in the terminal within the environment: "/path/to/your/java"
.
在具有相应环境内核的笔记本中,使用Sys.setenv(JAVA_HOME="/path/to/your/java")
继续!
In the notebook with the corresponding environment kernel, use Sys.setenv(JAVA_HOME="/path/to/your/java")
and go!
这篇关于如何在Jupyter Notebook内部的conda环境中使用特定的Java版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!