You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Periodic "bad interpreter" when caching virtual environments #182
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-python action changes, it invalidates the link between the virtual environment and the python binary.
Questions:
Is there a recommended method for caching dependencies with setup-python that will not suffer from this issue
Could you recommend file/something that can be hashed and added to the cache key to invalidate the cache when new python builds are pushed?
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.
In 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)
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-python installed, (b) I created my venv pointing to that version, (c) actions-cache cached 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.19 in my cached paths, like:
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).
Activity
olirice commentedon Jan 21, 2021
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#L55
I'd appreciate a nod if that's the recommended solution
rosik commentedon Jul 15, 2021
We 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.
Made venv cache dependent on exact python and os version.
Update github action poetry cache key
marcosschroh commentedon Apr 5, 2022
The same issue here.
Platform:
Version
v3Python
python3.7python3.8python3.9python3.10Any news?
panticmilos commentedon May 30, 2022
Hi @marcosschroh,
Just to let you know we are taking a deeper investigation into what is exactly happening here.
Cheers
panticmilos commentedon May 31, 2022
Hi again @marcosschroh,
Do you also use
actions/cachefor caching as other users? Also which package manager are you using?marcosschroh commentedon Jun 8, 2022
Hi,
I am using
pipandactions/cache@v3to cache the dependencies.vsafonkin commentedon Jun 9, 2022
Hi @marcosschroh, do you mean this workflow?
https://github.com/marcosschroh/dataclasses-avroschema/blob/master/.github/workflows/python-package.yml
As I see, you are using cache key without exact python version. So
venvhas config filepyvenv.cfgwith exact version and python path, for example:Your 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:
And after update of python patch version this cache will be rebuilt.
gha: fix issue when caching virtual environments
panticmilos commentedon Jun 22, 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
olirice commentedon Jun 22, 2022
using the output of
actions/setup-python@vXthat includes the patch version in the cache key sounds great. Thank you for the helpchance2021 commentedon Dec 16, 2022
In 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.
Use full python version to avoid bad interpreter errors.
Use full python version to avoid bad interpreter errors.
markfickett commentedon Sep 23, 2024
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: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.
Bump form-data to fix critical vulnerabilities #182 & #183 (#1163)
chore(deps): update actions/setup-python action to v6 (#11)
⬆️ Update actions/setup-python action to v6 (#21)