用jupyter notebook 打开pyspark

在~/.bash_profile中添加PYTHONPATH环境变量

export PYTHONPATH="/Users/yikunqin/Spark/spark-2.2.0-bin-hadoop2.7/python:$PYTHONPATH"
export PYTHONPATH="/Users/yikunqin/Spark/spark-2.2.0-bin-hadoop2.7/python/lib/py4j-0.10.4-src.zip:$PYTHONPATH"

添加之后,可以在命令行中运行python import pyspark,但是在jupyter notebook里面还是不能import pyspark


继续在~/.bash_profile中添加:

export PYSPARK_DRIVER_PYTHON="jupyter"

export PYSPARK_DRIVER_PYTHON_OPTS="notebook"

大概的意思就是用jupyter notebook来启动pyspark

最后在命令行中直接运行pyspark:

Spark/spark-2.2.0-bin-hadoop2.7/bin/pyspark

就可以从网页中打开jupyter notebook了,但是这种打开方式会自动新建一个SparkContext,所以要执行以下代码。先stop一个,再新建。

from pyspark import SparkContext
try:
    sc.stop()
except:
    pass
sc=SparkContext()
print("version: " + str(sc.version))

你可能感兴趣的:(小记录)