【发布时间】:2018-12-08 20:52:10
【问题描述】:
我正在尝试在 Jupyter Notebook 中运行以下 PySpark-Kafka 流 example。这是我在笔记本中使用的代码的第一部分:
from pyspark import SparkContext
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
sc = pyspark.SparkContext(master='local[*]',appName="PySpark streaming")
ssc = StreamingContext(sc, 2)
topic = "my-topic"
brokers = "localhost:9092"
kvs = KafkaUtils.createDirectStream(ssc, [topic], {"metadata.broker.list": brokers})
如果我运行单元格,我会收到以下错误/描述:
Spark Streaming's Kafka libraries not found in class path. Try one of the following.
1. Include the Kafka library and its dependencies with in the
spark-submit command as
$ bin/spark-submit --packages org.apache.spark:spark-streaming-kafka-0-8:2.3.0 ...
2. Download the JAR of the artifact from Maven Central http://search.maven.org/,
Group Id = org.apache.spark, Artifact Id = spark-streaming-kafka-0-8-assembly, Version = 2.3.0.
Then, include the jar in the spark-submit command as
$ bin/spark-submit --jars <spark-streaming-kafka-0-8-assembly.jar> ...
我的问题是:如何将 --jars 或 --package 参数传递给 Jupyter Notebook?或者,我可以下载这个包并将其永久链接到 Python/Jupyter(可能通过 .bashrc 中的导出)?
【问题讨论】:
标签: python apache-spark pyspark jupyter-notebook jupyter