在PyCharm IDE中添加Spark包

问题描述 投票:1回答:1

我根据in this link设置了我的PyCharm以连接我当地的火花装置

from pyspark import SparkContext, SQLContext, SparkConf
from operator import add
conf = SparkConf()
conf.setMaster("spark://localhost:7077")
conf.setAppName("Test")
sc = SparkContext(conf=conf)
sqlContext = SQLContext(sc)
df = sqlContext.createDataFrame([(2012, 8, "Batman", 9.8), (2012, 8, "Hero", 8.7), (2012, 7, "Robot", 5.5), (2011, 7, "Git", 2.0)],["year", "month", "title", "rating"])
df.write.mode('overwrite').format("com.databricks.spark.avro").save("file:///Users/abhattac/PycharmProjects/WordCount/users")

这需要将Databrick的avro jar发送到工作节点。我可以使用来自shell的spark-submit来完成它,如下所示:

/usr/local/Cellar/apache-spark/1.6.1/bin/pyspark AvroFile.py --packages com.databricks:spark-avro_2.10:2.0.1

当我从PyCharm IDE中运行它时,我无法找到如何提供--packages选项。任何帮助将不胜感激。

python pycharm pyspark pyspark-sql
1个回答
0
投票

您可以使用Python PYSPARK_SUBMIT_ARGS环境变量,通过使用PyCharm运行配置的环境变量部分(与您设置SPARK_HOME的地方相同)传递它

enter image description here

或者直接在你的代码中使用os.environ,如load external libraries inside pyspark code所示

© www.soinside.com 2019 - 2024. All rights reserved.