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

Azure DevOps流水线执行pip安装时找不到requirements.txt文件

解决Azure DevOps流水线中pip找不到requirements.txt的问题

问题根源

你的流水线同时checkout了两个仓库:

  • 流水线自身仓库被checkout到scripts-deploy目录
  • Mytest仓库被checkout到同名目录

执行pip install -r requirements.txt时,当前工作目录是Agent的根工作目录,而requirements.txt并不在这个根目录下,因此触发"文件或目录未找到"错误。

解决方案

根据requirements.txt所在的仓库,选择以下方式修正:

1. 切换到目标目录执行命令

如果requirements.txt在Mytest仓库中,修改script步骤:

- script: |
    python -m pip install --upgrade pip
    cd Mytest
    pip install -r requirements.txt

如果文件在流水线自身仓库(scripts-deploy目录)中,修改为:

- script: |
    python -m pip install --upgrade pip
    cd scripts-deploy
    pip install -r requirements.txt

2. 使用绝对路径指定文件

无需切换目录,直接通过完整路径引用requirements.txt:

# 假设文件在Mytest仓库
- script: |
    python -m pip install --upgrade pip
    pip install -r ./Mytest/requirements.txt

或者:

# 假设文件在scripts-deploy目录
- script: |
    python -m pip install --upgrade pip
    pip install -r ./scripts-deploy/requirements.txt

3. 明确checkout的工作目录(可选优化)

给Mytest的checkout步骤指定自定义路径,后续引用文件更清晰:

- checkout: Mytest
  path: mytest-repo

之后命令中可通过./mytest-repo/requirements.txt引用目标文件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 06:28:17