Azure Pipeline执行DBT模型Python脚本报错:py: command not found
排查Azure Pipeline中
py: command not found错误 核心原因
Azure Pipeline代理环境默认可能未配置py别名(py是Windows专属的Python启动器命令,Linux/macOS环境通常使用python或python3),或者代理机器未安装Python启动器。
解决方案
1. 替换py为对应Python命令
根据Pipeline使用的代理操作系统,直接使用匹配的Python命令:
- Windows代理:使用
python dbt_run.py或python3 dbt_run.py(若安装多版本Python) - Linux/macOS代理:使用
python3 dbt_run.py(Linux/macOS默认python指向Python2,推荐用python3)
2. 确保Pipeline中已安装Python
若代理机器未预装Python,需在Pipeline任务中先指定并安装Python版本:
- task: UsePythonVersion@0 inputs: versionSpec: '3.9' # 替换为你的项目依赖Python版本 addToPath: true - script: python dbt_run.py displayName: 'Execute dbt_Run.py script'
3. 检查自托管代理的Python环境
如果使用自托管代理,登录代理机器做以下确认:
- Windows:运行
where py查看py命令是否存在;若不存在,重新安装Python并勾选“Add Python to PATH”选项 - Linux/macOS:运行
which py验证命令是否存在;若不存在,手动将Python启动器路径添加到系统PATH
4. 直接指定Python可执行文件路径
若代理机器上Python路径明确,可直接使用绝对路径执行脚本:
# Windows示例 - script: 'C:\Python39\python.exe dbt_run.py' # Linux/macOS示例 - script: '/usr/bin/python3 dbt_run.py'
内容的提问来源于stack exchange,提问作者Rajas Patil
相关产品推荐
相关产品推荐

