3

I'm trying to cache the python dependencies of my project. To do that, I have this configuration in my workflow:

 - 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 

This works, by 'works' I mean that it loads the cache and skip the 'Install dependencies step' and it restores the ~/.cache/pip directory. The problem is that when I try to run the tests, the following error appears:

 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. 

Am I caching the incorrect directory? Or what am I doing wrong?

Note: this project is using python2.7 on Ubuntu 16.04

4
  • As the workflow defiintion you posted is not complete: are you running everything in the same job? Commented Jan 10, 2021 at 16:43
  • yeah, of course Commented Jan 10, 2021 at 16:44
  • I think you still have to run pip install. The difference is that pip will use the cache instead of redownloading the packages. After installing, the packages are stored in another folder, see stackoverflow.com/questions/29980798/… Commented Jan 10, 2021 at 17:11
  • And there is not a way to cache dependencies like in node with the node_modules folder? Commented Jan 10, 2021 at 17:23

1 Answer 1

1

As it explains here, you can cache the whole virtual environment:

- uses: actions/cache@v2 with: path: ${{ env.pythonLocation }} key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('dev-requirements.txt') }} 
Sign up to request clarification or add additional context in comments.

2 Comments

No, I tried it and it doesn't work for me. I have no env.pythonLocation variable in my github workflow.
You need to use the setup python action to have that variable

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.