おそらく、あなたのpython patが正しく設定されていないからでしょう。私は以下の関数が私のpython環境を設定するときに便利であることがわかります。
def configure_spark(spark_home=None, pyspark_python=None, conf_dir=None):
"""Configures the Python path for importing pyspark
Sets the SPARK_HOME and PYSPARK_PYTHON environment variables and modifies
the Python PATH so the pyspark package can be imported.
Args:
spark_home (str): Path of SPARK_HOME. Defaults to SPARK_HOME module
variable.
pyspark_python (str): Path to Python binary to use in PySpark. Defaults
to the currently executing Python binary.
conf_dir (str): Path to configuration directory
"""
# Set the configuration directory with some basic sanity checks:
if conf_dir:
if not os.path.isdir(conf_dir):
raise OSError("Spark config directory not found: %s" % conf_dir)
expected_conf = {'spark-env.sh', 'spark-defaults.conf'}
found_conf = expected_conf - set(os.listdir(conf_dir))
if found_conf:
warnings.warn("Some configuration files were not found: %s" % found_conf)
os.environ['SPARK_CONF_DIR'] = conf_dir
spark_home = spark_home or SPARK_HOME
os.environ['SPARK_HOME'] = spark_home
if not os.path.isdir(spark_home):
raise OSError("Specified SPARK_HOME is not a valid directory: %s" % spark_home)
# Add the PySpark directories to the Python path:
libs = glob(os.path.join(spark_home, 'python', 'lib', '*.zip'))
if len(libs) < 2:
raise OSError("Pyspark libraries not found in %s" % spark_home)
for lib in libs:
sys.path.insert(1, lib)
# If PYSPARK_PYTHON isn't specified, use currently running Python binary:
pyspark_python = pyspark_python or sys.executable
os.environ['PYSPARK_PYTHON'] = pyspark_python
@なぜアップヴォートがないのか分かりませんが、この機能は素晴らしいです、あなた自身で書きましたか? – Tbaki
@Tbaki私はこの問題に何度も遭遇してしまったので、そうでした。私は実際にそれがpysparkコードにないことにショックを受けました。彼らは今までにそれを追加したかもしれない。 – santon
私の知るところではありませんが、これはpysparkをインストールしようとするすべての人に与えなければならない、私は他の方法で得たすべての問題から私を救った。あなたのメソッドのために多くのおかげで、私は私の周りにそれをrecomandするよ!しかし、どのようにそれに値する注意を払うか分からない。 :/ – Tbaki