我对 Pyspark 很陌生。我正在使用 Anaconda 执行一段 Pyspark 代码。我正在尝试启动 SparkContext 。这会引发下面列出的错误。看起来这个错误在 Python 中很正常,但我无法在 Pyspark 的上下文中弄清楚。代码是这样的:
import findspark
findspark.init()
import pyspark
import random
import os
import sys
sc = pyspark.SparkContext(appName="Pi")
仅执行此操作会引发如下错误:
---------------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-6-3fc08890af27> in <module>()
----> 1 sc = pyspark.SparkContext(appName="Pi")
C:\opt\spark\spark-2.3.0-bin-hadoop2.7\python\pyspark\context.py in __init__(self, master, appName, sparkHome, pyFiles, environment, batchSize, serializer, conf, gateway, jsc, profiler_cls)
113 """
114 self._callsite = first_spark_call() or CallSite(None, None, None)
--> 115 SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
116 try:
117 self._do_init(master, appName, sparkHome, pyFiles, environment, batchSize, serializer,
C:\opt\spark\spark-2.3.0-bin-hadoop2.7\python\pyspark\context.py in _ensure_initialized(cls, instance, gateway, conf)
278 with SparkContext._lock:
279 if not SparkContext._gateway:
--> 280 SparkContext._gateway = gateway or launch_gateway(conf)
281 SparkContext._jvm = SparkContext._gateway.jvm
282
C:\opt\spark\spark-2.3.0-bin-hadoop2.7\python\pyspark\java_gateway.py in launch_gateway(conf)
58 submit_args
59 ])
---> 60 command = command + shlex.split(submit_args)
61
62 # Start a socket that will be used by PythonGatewayServer to communicate its port to us
UnboundLocalError: local variable 'submit_args' referenced before assignment