无法从 Spark 提交中的 JAR 文件加载 main class

Cannot load main class from JAR file in Spark Submit

我正在尝试 运行 Spark 作业。这是我的 shell 脚本,位于 /home/full/path/to/file/shell/my_shell_script.sh:

confLocation=../conf/my_config_file.conf &&
executors=8 &&
memory=2G &&
entry_function=my_function_in_python &&
dos2unix $confLocation &&
spark-submit \
        --master yarn-client \
        --num-executors $executors \
        --executor-memory $memory \
        --py-files /home/full/path/to/file/python/my_python_file.py $entry_function $confLocation

当我 运行 这样做时,我收到一条错误消息:

Error: Cannot load main class from JAR file: /home/full/path/to/file/shell/my_function_in_python

我的印象是它在错误的地方查找(python 文件位于 python 目录,而不是 shell 目录)。

--py-files 标志用于从您的程序中使用的 附加 python 文件依赖项;你可以看到 here in SparkSubmit.scala 它使用所谓的 "primary argument",意思是第一个非标志参数,来确定是执行 "submit jarfile" 模式还是 "submit python main" 模式。

这就是为什么您看到它试图将您的“$entry_function”加载为不存在的 jar 文件的原因,因为它只假设您是 运行 Python 如果那主要参数以“.py”结尾,否则默认假设您有一个 .jar 文件。

不要使用 --py-files,只需让 /home/full/path/to/file/python/my_python_file.py 成为主要参数即可;那么你可以花式 python 将 "entry function" 作为程序参数,或者你只是在 python 文件本身的主函数中调用你的入口函数。

或者,您仍然可以使用 --py-files,然后创建一个调用入口函数的新主 .py 文件,然后将该主 .py 文件作为主要参数传递。

对我有用的是在没有 --py-files 命令的情况下简单地传递 python 文件。 看起来像这样:

confLocation=../conf/my_config_file.conf &&
executors=8 &&
memory=2G &&
entry_function=my_function_in_python &&
dos2unix $confLocation &&
spark-submit \
        --master yarn-client \
        --num-executors $executors \
        --executor-memory $memory \
        /home/full/path/to/file/python/my_python_file.py $entry_function $confLocation

在--py-files中添加元素时使用逗号分隔,不留任何space。试试这个:

confLocation=../conf/my_config_file.conf &&
executors=8 &&
memory=2G &&
entry_function=my_function_in_python &&
dos2unix $confLocation &&
spark-submit \
        --master yarn-client \
        --num-executors $executors \
        --executor-memory $memory \
        --py-files /home/full/path/to/file/python/my_python_file.py,$entry_function,$confLocation