You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Azure App Service WebJobs中运行Python任务的报错问题

问题

在Azure App Service的Linux环境(Basic计划、Python运行时、Code部署模型)中,上传包含Python脚本的ZIP包创建WebJob后运行报错,错误日志如下:

[11/18/2024 23:23:22 > d7204e: SYS INFO] Status changed to Initializing
[11/18/2024 23:23:22 > d7204e: SYS INFO] Run script 'run.py' with script host - 'PythonScriptHost'
[11/18/2024 23:23:22 > d7204e: SYS INFO] Status changed to Running
[11/18/2024 23:23:22 > d7204e: ERR ] An error occurred trying to start process 'python.exe' with working directory '/tmp/jobs/triggered/webjobpy/bphw5fzr.pno/webjobtest'. No such file or directory

推测问题是Linux环境下找不到python.exe,需解决该报错并确认WebJobs是否支持Python任务。

解决方案
  • 指定Linux兼容的Python可执行文件:Linux系统中没有python.exe,需使用python3或python(取决于App Service配置的Python版本),可通过两种方式配置:
    1. 给WebJob添加启动脚本:在ZIP包中创建run.sh文件,内容为:
      #!/bin/bash
      python3 run.py
      
      本地执行chmod +x run.sh赋予脚本可执行权限后再打包上传,WebJob会优先执行该脚本。
    2. 修改WebJob运行命令:创建WebJob时,将默认的脚本执行命令改为python3 run.py,而非直接指定run.py。
  • 验证Python运行时可用性:通过App Service的SSH连接进入容器,执行which python3确认可执行文件路径是否存在,同时检查App Service配置中是否正确启用了目标版本的Python运行时。
  • 明确WebJobs对Python的支持性:Azure WebJobs完全支持Python任务,本次报错仅因默认脚本主机误用了Windows平台的python.exe命令,适配Linux环境的可执行文件名称即可解决。

内容的提问来源于stack exchange,提问作者okake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 01:14:55