Pyspark, initializing spark programmetically : IllegalArgumentException: Missing application resource
<p>When creating a spark context in Python, I get the following error.</p>

<pre><code> app_name="my_app"
 master="local[*]"
 sc = SparkContext(appName=app_name, master=master)

Exception in thread "main" java.lang.IllegalArgumentException: Missing application resource.
at org.apache.spark.launcher.CommandBuilderUtils.checkArgument(CommandBuilderUtils.java:241)
at org.apache.spark.launcher.SparkSubmitCommandBuilder.buildSparkSubmitArgs(SparkSubmitCommandBuilder.java:160)
at org.apache.spark.launcher.SparkSubmitCommandBuilder.buildSparkSubmitCommand(SparkSubmitCommandBuilder.java:276)
at org.apache.spark.launcher.SparkSubmitCommandBuilder.buildCommand(SparkSubmitCommandBuilder.java:151)
at org.apache.spark.launcher.Main.main(Main.java:86)

....

pyspark.zip/pyspark/java_gateway.py", line 94, in launch_gateway
raise Exception("Java gateway process exited before sending the driver its port number")
Exception: Java gateway process exited before sending the driver its port number
</code></pre>

<p>The spark launcher seems to be failing somehow.</p>

<p>This was happening due to preexisting env variables, that conflicted. I deleted them in the python program and it works smoothly now.</p>

<p>ex:</p>

<pre><code>import  os
#check if pyspark env vars are set and then reset to required or delete.   
del os.environ['PYSPARK_SUBMIT_ARGS']
</code></pre>

python pyspark