gpt4 book ai didi

python - 在 Oozie 中运行 python 脚本时如何导入本地 python 模块?

转载 作者:行者123 更新时间:2023-11-28 20:39:59 25 4
gpt4 key购买 nike

我有两个 python 文件 - my_python_A.py 和 my_python_B.py。第一个文件引用第二个文件(from my_python_B import *)。

我正在从 Oozie 中的 shell 操作执行第一个 python 文件(即脚本只是 python my_python_A.py),并且收到以下错误:

Traceback (most recent call last):
File "my_python_A.py", line 2, in <module>
from my_python_B import *
ImportError: No module named my_python_B
Failing Oozie Launcher, Main class [org.apache.oozie.action.hadoop.ShellMain], exit code [1]

两个 python 文件都位于 HDFS 中的同一目录下。我怎样才能使这个导入语句起作用?

最佳答案

我遇到了同样的问题,解决这个问题的方法是设置环境变量 PYTHONPATH在我执行 python 代码之前到 shell 脚本中的当前工作目录

export PYTHONPATH=`pwd`
python m_python_A.py

确保在您的 shell 操作中,您已将所有必需的 python 模块包含在 <file></file> 中标签。假设您有一个名为 sample_script.sh 的 shell 脚本(其中包含上述命令),您的 workflow.xml 文件应该如下所示

<workflow-app name="shellTest" xmlns="uri:oozie:workflow:0.4">
<start to="shell-action"/>
<action name="shell-action">
<shell xmlns="uri:oozie:shell-action:0.2">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>oozie.launcher.mapred.job.queue.name</name>
<value>${launcherqueue}</value>
</property>
<property>
<name>mapred.job.queue.name</name>
<value>${mapredqueue}</value>
</property>
</configuration>
<exec>sample_script.sh</exec>
<file>${appPath}/sample_script.sh#sample_script.sh</file>
<file>${appPath}/m_python_A.py#m_python_A.py</file>
<file>${appPath}/m_python_B.py#m_python_B.py</file>
<capture-output/>
</shell>
<ok to="end"/>
<error to="shell-action-failed"/>
</action>

<kill name="shell-action-failed">
<message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>

<end name="end" />

</workflow-app>

关于python - 在 Oozie 中运行 python 脚本时如何导入本地 python 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36848053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com