错误:必须指定主要资源(JAR 或 Python 或 R 文件) - IPython 笔记本

2024-03-31

我尝试在 IPython Notebook 中运行 Apache Spark,请遵循此说明(以及评论中的所有建议)-link http://ramhiser.com/2015/02/01/configuring-ipython-notebook-support-for-pyspark/

但是当我通过以下命令运行 IPython Notebook 时:

ipython notebook --profile=pyspark

我收到此错误:

Error: Must specify a primary resource (JAR or Python or R file)

如果我在 shell 中运行 pyspark,一切正常。这意味着我在连接 Spark 和 IPython 时遇到了一些问题。

顺便说一句,这是我的 bash_profile:

export SPARK_HOME="$HOME/spark-1.4.0"
export PYSPARK_SUBMIT_ARGS='--conf "spark.mesos.coarse=true" pyspark-shell'

而这包含〜/.ipython/profile_pyspark/startup/00-pyspark-setup.py:

# Configure the necessary Spark environment
import os
import sys

# Spark home
spark_home = os.environ.get("SPARK_HOME")

# If Spark V1.4.x is detected, then add ' pyspark-shell' to
# the end of the 'PYSPARK_SUBMIT_ARGS' environment variable
spark_release_file = spark_home + "/RELEASE"
if os.path.exists(spark_release_file) and "Spark 1.4" in  open(spark_release_file).read():
    pyspark_submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS", "")
    if not "pyspark-shell" in pyspark_submit_args: pyspark_submit_args += " pyspark-shell"
    os.environ["PYSPARK_SUBMIT_ARGS"] = pyspark_submit_args

# Add the spark python sub-directory to the path
sys.path.insert(0, spark_home + "/python")

# Add the py4j to the path.
# You may need to change the version number to match your install
sys.path.insert(0, os.path.join(spark_home, "python/lib/py4j-0.8.2.1-src.zip"))

# Initialize PySpark to predefine the SparkContext variable 'sc'
execfile(os.path.join(spark_home, "python/pyspark/shell.py"))

以及可能需要什么 - 昨天我将我的 OS X 升级到 10.10.4


我遇到了类似的问题并且使用了相同的方法00-pyspark-setup.py与使用时的文件spark-1.4.0.

正如 Philippe Rossignol 的评论所解释的那样这个博客 http://ramhiser.com/2015/02/01/configuring-ipython-notebook-support-for-pyspark/, 以下几行已添加到00-pyspark-setup.py文件 自从争论以来pyspark-shell需要用于PYSPARK_SUBMIT_ARGS:

# If Spark V1.4.x is detected, then add ' pyspark-shell' to
# the end of the 'PYSPARK_SUBMIT_ARGS' environment variable
spark_release_file = spark_home + "/RELEASE"
if os.path.exists(spark_release_file) and "Spark 1.4" in open(spark_release_file).read():
    pyspark_submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS", "")
    if not "pyspark-shell" in pyspark_submit_args: pyspark_submit_args += " pyspark-shell"
    os.environ["PYSPARK_SUBMIT_ARGS"] = pyspark_submit_args

然而在我的内心spark-1.4.0文件夹,没有RELEASE文件,所以if附加条件pyspark-shell to PYSPARK_SUBMIT_ARGS从来没有满足过。

作为一个笨拙的解决方案,我只是注释掉了检查发布文件的行,因此只留下了以下几行:

pyspark_submit_args = os.environ.get("PYSPARK_SUBMIT_ARGS", "")
if not "pyspark-shell" in pyspark_submit_args: pyspark_submit_args += " pyspark-shell"
os.environ["PYSPARK_SUBMIT_ARGS"] = pyspark_submit_args
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误:必须指定主要资源(JAR 或 Python 或 R 文件) - IPython 笔记本 的相关文章

随机推荐