在Azure Linux WebApp中运行Python WebJob时遇执行错误
问题描述
在Azure Linux WebApp中运行Python WebJob时出现如下错误:
Run script 'webjob.py' with script host - 'PythonScriptHost'
f24041: SYS INFO] Status changed to Running
f24041: ERR ] An error occurred trying to start process 'python.exe' with working directory '/tmp/jobs/continuous/test/qsinu4ck.4pl'. No such file or directory
f24041: SYS ERR ] System.AggregateException: One or more errors occurred. (An error occurred trying to start process 'python.exe' with working directory '/tmp/jobs/continuous/test/qsinu4ck.4pl'. No such file or directory)
---> System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'python.exe' with working directory '/tmp/jobs/continuous/test/qsinu4ck.4pl'. No such file or directory
解决方法
- 替换Python可执行文件名称:Linux环境下不存在
python.exe,改用python3或python(取决于系统默认映射)。修改WebJob启动命令,比如将python.exe webjob.py改为python3 webjob.py。 - 指定Python绝对路径:通过SSH连接WebApp实例,执行
which python3获取Python绝对路径(如/usr/bin/python3),将启动命令改为该路径调用脚本,比如/usr/bin/python3 webjob.py。 - 检查工作目录有效性:确认错误中提到的
/tmp/jobs/continuous/test/qsinu4ck.4pl目录是否存在,若不存在则手动创建,或修改WebJob的工作目录配置。 - 验证Python环境安装:通过SSH进入实例执行
python3 --version,确认Python已正确安装。若未安装,可通过WebApp扩展或自定义脚本安装对应版本。 - 检查WebJob配置文件:如果使用
settings.job配置文件,确保command字段使用Linux兼容的Python调用命令,避免Windows环境的python.exe写法。
内容的提问来源于stack exchange,提问作者user29140482

