【发布时间】:2015-04-21 21:33:55
【问题描述】:
我点击此链接http://ramhiser.com/2015/02/01/configuring-ipython-notebook-support-for-pyspark/ 为 IPython 创建 PySpark 配置文件。
00-pyspark-setup.py
# Configure the necessary Spark environment
import os
import sys
spark_home = os.environ.get('SPARK_HOME', None)
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'))
当我在 ipython-notebook 中输入 sc 时,我的问题是 '' 我应该看到类似于 <pyspark.context.SparkContext at 0x1097e8e90>. 的输出
关于如何解决它的任何想法?
【问题讨论】:
-
你想达到什么目的。您的代码中哪里出现问题?
-
@Rias 我更新了我的问题
-
在 Python 3 中删除了 execfile,因此最后一行必须更改为 exec(open(os.path.join(spark_home, '\python\pyspark\shell.py')).read() )。
标签: python apache-spark