Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Spark packages in PyCharm IDE

I have set up my PyCharm to link with my local spark installation as per in this link

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")

This requires Databrick's avro jar to be shipped to worker node. I can get it done using spark-submit from shell like the following:

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

I couldn't find out how to provide --packages option when I am running it from inside PyCharm IDE. Any help will be appreciated.

like image 963
user3138594 Avatar asked May 10 '26 07:05

user3138594


1 Answers

You can use Python PYSPARK_SUBMIT_ARGS environment variable, either by passing it using environment variables section of the PyCharm run configuration (the same place where you set SPARK_HOME)

enter image description here

or using os.environ directly in your code as shown in load external libraries inside pyspark code

like image 74
2 revszero323 Avatar answered May 12 '26 20:05

2 revszero323



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!