Skip to content

Commit 51ebb26

Browse files
committed
Ship pyspark archives and add it to PYTHONPATH
1 parent 413fa25 commit 51ebb26

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

core/src/main/scala/org/apache/spark/api/python/PythonUtils.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ private[spark] object PythonUtils {
3535
pythonPath += Seq(sparkHome, "python", "lib", "py4j-0.8.2.1-src.zip").mkString(File.separator)
3636
}
3737
pythonPath ++= SparkContext.jarOfObject(this)
38+
sys.env.get("PYSPARK_ARCHIVES_PATH") match {
39+
case Some(path) => pythonPath += path
40+
case None => // do nothing
41+
}
3842
pythonPath.mkString(File.pathSeparator)
3943
}
4044

yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,6 @@ private[spark] class Client(
371371
env(ENV_DIST_CLASSPATH) = dcp
372372
}
373373

374-
sys.env.get("PYTHONPATH") match {
375-
case Some(pythonPath) => env("PYTHONPATH") = pythonPath
376-
case None => // do nothing
377-
}
378-
379374
env
380375
}
381376

yarn/src/main/scala/org/apache/spark/deploy/yarn/ExecutorRunnable.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ class ExecutorRunnable(
7575

7676
val localResources = prepareLocalResources
7777
ctx.setLocalResources(localResources)
78-
78+
// From SPARK-1920 and SPARK-1520 we know PySpark on Yarn can not work when the assembly jar are
79+
// package by JDK 1.7+, so we ship PySpark archives to executors by Yarn with --py-files, and
80+
// add this path to PYTHONPATH.
81+
for ((k, v) <- localResources if k.contains("spark-pyspark")) {
82+
env("PYSPARK_ARCHIVES_PATH") = k
83+
}
7984
ctx.setEnvironment(env)
8085

8186
val credentials = UserGroupInformation.getCurrentUser().getCredentials()
@@ -299,12 +304,6 @@ class ExecutorRunnable(
299304
}
300305

301306
System.getenv().filterKeys(_.startsWith("SPARK")).foreach { case (k, v) => env(k) = v }
302-
303-
sys.env.get("PYTHONPATH") match {
304-
case Some(pythonPath) => env("PYTHONPATH") = pythonPath
305-
case None => // do nothing
306-
}
307-
308307
env
309308
}
310309
}

0 commit comments

Comments
 (0)