【发布时间】:2019-09-22 02:15:22
【问题描述】:
当我创建一个 Spark 会话时,它会抛出一个错误
无法创建 Spark 会话
使用
pyspark,代码sn-p:
ValueError Traceback (most recent call last)
<ipython-input-13-2262882856df> in <module>()
37 if __name__ == "__main__":
38 conf = SparkConf()
---> 39 sc = SparkContext(conf=conf)
40 # print(sc.version)
41 # sc = SparkContext(conf=conf)
~/anaconda3/lib/python3.5/site-packages/pyspark/context.py in __init__(self, master, appName, sparkHome, pyFiles, environment, batchSize, serializer, conf, gateway, jsc, profiler_cls)
131 " note this option will be removed in Spark 3.0")
132
--> 133 SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
134 try:
135 self._do_init(master, appName, sparkHome, pyFiles, environment, batchSize, serializer,
~/anaconda3/lib/python3.5/site-packages/pyspark/context.py in _ensure_initialized(cls, instance, gateway, conf)
330 " created by %s at %s:%s "
331 % (currentAppName, currentMaster,
--> 332 callsite.function, callsite.file, callsite.linenum))
333 else:
334 SparkContext._active_spark_context = instance
ValueError: Cannot run multiple SparkContexts at once; existing SparkContext(app=pyspark-shell, master=local[*]) created by __init__ at <ipython-input-7-edf43bdce70a>:33
- 进口
from pyspark import SparkConf, SparkContext
- 我尝试了这种替代方法,但也失败了:
spark = SparkSession(sc).builder.appName("Detecting-Malicious-URL App").getOrCreate()
这是抛出另一个错误,如下所示:
NameError: name 'SparkSession' is not defined
【问题讨论】:
-
试试这个:从 pyspark.sql 导入 SparkSession
标签: python machine-learning networking pyspark jupyter-notebook