Search code examples
pythonapache-sparkpysparkvirtualenvspark-submit

Spark-Submit : Cannot run with virtualenv


I have a python app that i want to run via a viratual environment using spark submit. Here is my command

PYSPARK_PYTHON=./venv/bin/python spark-submit --conf spark.yarn.appMasterEnv.PYSPARK_PYTHON=./venv/bin/python --master yarn --deploy-mode cluster --archives venv.zip#venv test.py

here, venv.zip is the archived virtual environment. Now when i run the spark-submit command, i get this on the console

20/01/28 17:08:12 INFO org.apache.hadoop.yarn.client.RMProxy: Connecting to ResourceManager at myMasterNode/some.ip:somePort
20/01/28 17:08:13 INFO org.apache.hadoop.yarn.client.AHSProxy: Connecting to Application History server at myMasterNode/some.ip:somePort
20/01/28 17:08:16 INFO org.apache.hadoop.yarn.client.api.impl.YarnClientImpl: Submitted application application_1580155727514_5620
Exception in thread "main" org.apache.spark.SparkException: Application application_1580155727514_5620 finished with failed status
    at org.apache.spark.deploy.yarn.Client.run(Client.scala:1165)
    at org.apache.spark.deploy.yarn.YarnClusterApplication.start(Client.scala:1520)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:894)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:198)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:228)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:137)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

and on the yarn log, this is what i see

20/01/28 17:08:53 ERROR org.apache.spark.deploy.yarn.ApplicationMaster: User class threw exception: java.io.IOException: Cannot run program "./signal/bin/python": error=2, No such file or directory
java.io.IOException: Cannot run program "./venv/bin/python": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

what am i doing wrong ? How can i make sure that the venv.zip is being copied and unzipped properly ?


Solution

  • the unzip put a venv dir inside #venv.

    so should spark.yarn.appMasterEnv.PYSPARK_PYTHON=./venv/venv/bin/python

    if you change zip to tar.gz, this problem will go away