pyspark 2.0 and later execute the script file in the environment variable PYTHONSTARTUP , so you can run:
PYTHONSTARTUP=code.py pyspark
Compared to spark-submit answer, this is useful for running initialization code before using the pyspark interactive shell.
source share