GitHub Actions执行报错:找不到requirements.txt文件求助
问题原因
你把requirements.txt、ci.py都放在了.github/workflows/目录下,但GitHub Actions执行时默认工作目录是仓库根目录,不是.github/workflows/。当Workflow里执行pip install -r requirements.txt时,pip会在根目录找文件,自然找不到,所以报错。
解决方法
方法1:调整文件位置(推荐)
把ci.py和requirements.txt移到仓库根目录,.github/workflows/ci.yaml留在原位置。这样Workflow默认目录就能直接找到这两个文件,不用改命令。
方法2:指定文件路径
不想移动文件的话,在pip命令里明确写requirements.txt的完整路径:
# 在ci.yaml的安装步骤修改命令 - name: Install dependencies run: pip install -r .github/workflows/requirements.txt
运行ci.py时也要指定路径:
- name: Run script run: python .github/workflows/ci.py
方法3:切换工作目录
在Workflow步骤里先切换到.github/workflows/目录,再执行命令,注意要把命令放在同一个shell会话里:
- name: Install and run run: | cd .github/workflows/ pip install -r requirements.txt python ci.py
内容的提问来源于stack exchange,提问作者Gregory Morris
相关产品推荐
相关产品推荐

