Repository navigation
Periodic "bad interpreter" when caching virtual environments #182
Description
Activity
The folks over at poetry seem to have run into the same issue
They do this:
https://github.com/python-poetry/poetry/blob/master/.github/workflows/main.yml#L55I'd appreciate a nod if that's the recommended solution
Reacted by Marcos SchrohWe usually encounter the same problem.
I guess it's connected to some external event, like Github runners update or something similar.
After that, the workflow starts to fail steadily with the same error mentioned above.We usually fix it by updating the cache key, but it's really annoying.
- added a commit that references this issue
on Oct 4, 2021 - added a commit that references this issue
on Jan 19, 2022 The same issue here.
Platform:
- Ubuntu
Version
-
v3
Python
-
python3.7 -
python3.8 -
python3.9 -
python3.10
Any news?
Hi @marcosschroh,
Just to let you know we are taking a deeper investigation into what is exactly happening here.
Cheers
Reacted by Marcos SchrohHi again @marcosschroh,
Do you also use
actions/cachefor caching as other users? Also which package manager are you using?Hi,
I am using
pipandactions/cache@v3to cache the dependencies.Hi @marcosschroh, do you mean this workflow?
https://github.com/marcosschroh/dataclasses-avroschema/blob/master/.github/workflows/python-package.ymlAs I see, you are using cache key without exact python version. So
venvhas config filepyvenv.cfgwith exact version and python path, for example:home = /opt/hostedtoolcache/Python/3.10.4/x64/bin include-system-site-packages = false version = 3.10.4Your workflow has only major.minor python version and after update python patch version, for example 3.10.4 -> 3.10.5 your venv cache will break.
You should create key with exact python version, for example:
- uses: actions/setup-python@v4 id: cp310 with: python-version: "3.10" - uses: actions/cache@v3 id: cache # name for referring later with: path: .venv key: ${{ runner.os }}-cache-${{ steps.cp310.outputs.version }}-${{ hashFiles('requirements.txt') }}
And after update of python patch version this cache will be rebuilt.
Reacted by Giovanni Totaro - aka Vanni- added a commit that references this issue
on Jun 18, 2022 Hi @olirice,
Since there is no recent activity on this issue, I am going to close it. Feel free to continue the discussion if you have additional questions.
Cheers
using the output of
actions/setup-python@vXthat includes the patch version in the cache key sounds great. Thank you for the helpIn my case, the error shows in Github action and the root cause is the broken python symbolic link. As a workaround, I just simply re-create it during the process.
Error: home/runner/work/_temp/810926a2-36c5-4488-ac84-6f3f57713147.sh: /home/runner/work/dataops/dataops/.venv/bin/pytest: /home/runner/work/dataops/dataops/.venv/bin/python: bad interpreter: No such file or directory Root Cause: /home/runner/work/dataops/dataops/.venv/bin/python: broken symbolic link to /opt/hostedtoolcache/Python/3.9.15/x64/bin/python3.9 Solution: Add below scripts into wherever has broken link: PYTHON_PATH=$(which python3) source .venv/bin/activate PYTHON_BROKEN_PATH=$(dirname $(which pip)) rm $PYTHON_BROKEN_PATH/python ln -s $PYTHON_PATH $PYTHON_BROKEN_PATH/python export PATH=$PATH:$(dirname $PYTHON_BROKEN_PATH)- added 2 commits that reference this issue
on Dec 8, 2023 I ran into this. It turned out to be because I was using setup-python to install my Python version when I was doing my cached venv setup.
It was installing into
/opt/hostedtoolcache/Python/3.9.19, and I think that used to be a default version on the GH runners, but the default just updated. So, (a)setup-pythoninstalled, (b) I created my venv pointing to that version, (c)actions-cachecached the venv symlink but not the installed version, and finally (d) when I restored the cache the symlink was broken because the Python binary wasn't included.So, the fix was to include
/opt/hostedtoolcache/Python/3.9.19in my cached paths, like:path: | venv ~/.ssl .env /opt/hostedtoolcache/Python/3.9.19
Note the path must be the same literal value in restores, with no vars as used, as in the cache action. Otherwise it will not match (but will report the same cache key as was generated).
I found debugging with SSH useful along the way.
- added a commit that references this issue
on Apr 17, 2026 - added a commit that references this issue
on Jul 4, 2026
Describe the bug
When testing large projects it is convenient to cache dependencies from pypi with a cache key based on the projects
setup.py. I've been been using that pattern (yaml shown below) on several projects for > 6 months. It works great, but periodically (every 1-6 weeks) fails with the error:Once the error occurs once, it will appear consistently until I alter the cache key and force the virtual environment to rebuild.
I think what's happening is that every time the build/setup for the
setup-pythonaction changes, it invalidates the link between the virtual environment and the python binary.Questions:
setup-pythonthat will not suffer from this issueThanks!
Which version of the action are you using?
v1v2v2.0.1ormaster)Environment
Python Versions
At least all versions of 3.7 and 3.8 but probably all of them