I can run my python+pyspark script from the unix command line by typing
pyspark script.py
But how do I run script.py from within the pyspark shell? This seems like an elementary question but I can't find the answer anywhere. I tried
execfile('script.py')
But I get an error which includes:
ValueError: Cannot run multiple SparkContexts at once
subprocess.call(docs.python.org/3/library/subprocess.html#subprocess.call). My understanding is thatexecfiletries to evaluate the file in the same Python instance, whereas with thesubprocessmodule you can spawn another instance of Python and PySpark, without any conflict.subprocesswill only help you invoke another spark program. You could try something similar tosubprocess.Popenwithstdout=PIPE