无法从Spark提交的JAR文件加载主类

2024-10-02 22:35:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试着做一份有创意的工作。这是我的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目录)。


Tags: topathinpyhomemyconffunction
3条回答

--py-files标志用于程序中使用的附加的python文件依赖项;您可以看到here in SparkSubmit.scala它使用所谓的“主参数”(即第一个非标志参数)来确定是执行“submit jarfile”模式还是“submit python main”模式。

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

不要使用--py-files,只需将/home/full/path/to/file/python/my_python_file.py作为主参数;然后您可以使用python将“entry function”作为程序参数,也可以在python文件本身的主函数中调用entry函数。

或者,您仍然可以使用--py-files,然后创建一个新的主.py文件来调用entry函数,然后将该主.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文件时,使用逗号分隔元素,而不留任何空格。试试这个:

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

相关问题 更多 >