【发布时间】:2021-04-15 17:25:29
【问题描述】:
我正在尝试缓存我的项目的 python 依赖项。为此,我的工作流程中有以下配置:
- uses: actions/cache@v2
id: cache
with:
path: ~/.cache/pip
key: pip-${{ runner.os }}-${{ hashFiles('**/requirements.txt') }}-${{ hashFiles('**/requirements_dev.txt') }}
restore-keys: pip-${{ runner.os }}
- name: Install apt dependencies
run: |
sudo apt-get update
sudo apt-get install gdal-bin
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
pip install --upgrade pip==9.0.1
pip install -r requirements.txt
pip install -r requirements_dev.txt
这有效,“有效”是指它加载缓存并跳过“安装依赖项步骤”并恢复~/.cache/pip 目录。问题是当我尝试运行测试时,出现以下错误:
File "manage.py", line 7, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
Error: Process completed with exit code 1.
我是否缓存了不正确的目录?还是我做错了什么?
注意:本项目在 Ubuntu 16.04 上使用 python2.7
【问题讨论】:
-
由于您发布的工作流定义不完整:您是否在同一个作业中运行所有内容?
-
是的,当然
-
我认为您仍然需要运行 pip install。不同之处在于 pip 将使用缓存而不是重新下载包。安装后,包存放在另一个文件夹中,见stackoverflow.com/questions/29980798/…
-
并且没有办法像在 node_modules 文件夹中那样缓存依赖项?
标签: python caching pip github-actions