GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Periodic "bad interpreter" when caching virtual environments · Issue #182 · actions/setup-python

Periodic "bad interpreter" when caching virtual environments #182

New issue
Copy link
New issue
Copy link
Closed
Closed
Periodic "bad interpreter" when caching virtual environments#182
Copy link
Assignees
panticmilos
Labels
bugSomething isn't workingSomething isn't working

Description

@olirice
olirice
opened on Jan 21, 2021
Issue body actions

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:

Screen Shot 2021-01-21 at 6 00 02 AM

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?
    steps:

    - name: set up python 3.8
      uses: actions/setup-python@v1
      with:
        python-version: 3.8

    - name: checkout
      uses: actions/checkout@v2

    - name: cache dependencies
      id: xyz-cache
      uses: actions/cache@v2
      with:
        path: venv
        key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-0

    - name: install xyz
      if: steps.sl-cache.outputs.cache-hit != 'true'
      run: |
        python -m venv venv
        source venv/bin/activate
        python -m pip install --U pip setuptools wheel
        pip install -e ".[dev]"

Thanks!

Which version of the action are you using?

  • v1
  • v2
  • Some other tag (such as v2.0.1 or master)

Environment

  • self-hosted
  • Linux
  • Windows
  • Mac

Python Versions
At least all versions of 3.7 and 3.8 but probably all of them

Reacted by Marcos Schroh
Reacted by Yaroslav Dynnikov, kw, Mike Lissner and dhirajbhakta-arcana

Activity

  1. olirice
    added
    bugSomething isn't workingSomething isn't working
    on Jan 21, 2021
  2. olirice commented on Jan 21, 2021

    @olirice
    olirice
    on Jan 21, 2021
    Author
    More actions

    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

    Reacted by Marcos Schroh
  3. rosik commented on Jul 15, 2021

    @rosik
    rosik
    on Jul 15, 2021
    More actions

    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.

  4. nuwang
    added a commit that references this issue on Oct 4, 2021

    Made venv cache dependent on exact python and os version.

    baf5bc6
  5. werneta
    added a commit that references this issue on Jan 19, 2022

    Update github action poetry cache key

    b8c4d87
  6. marcosschroh commented on Apr 5, 2022

    @marcosschroh
    marcosschroh
    on Apr 5, 2022
    More actions

    The same issue here.

    Platform:

    • Ubuntu

    Version

    • v3

    Python

    • python3.7
    • python3.8
    • python3.9
    • python3.10

    Any news?

  7. marko-zivic-93
    self-assigned this
    on May 5, 2022
  8. marko-zivic-93
    assigned
    panticmilos
    and unassigned
    marko-zivic-93
    on May 25, 2022
  9. panticmilos commented on May 30, 2022

    @panticmilos
    panticmilos
    on May 30, 2022
    Contributor
    More actions

    Hi @marcosschroh,

    Just to let you know we are taking a deeper investigation into what is exactly happening here.

    Cheers

    Reacted by Marcos Schroh
  10. panticmilos commented on May 31, 2022

    @panticmilos
    panticmilos
    on May 31, 2022
    Contributor
    More actions

    Hi again @marcosschroh,

    Do you also use actions/cache for caching as other users? Also which package manager are you using?

  11. marcosschroh commented on Jun 8, 2022

    @marcosschroh
    marcosschroh
    on Jun 8, 2022
    More actions

    Hi,

    I am using pip and actions/cache@v3 to cache the dependencies.

  12. vsafonkin commented on Jun 9, 2022

    @vsafonkin
    vsafonkin
    on Jun 9, 2022
    More actions

    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 venv has config file pyvenv.cfg with exact version and python path, for example:

    home = /opt/hostedtoolcache/Python/3.10.4/x64/bin
    include-system-site-packages = false
    version = 3.10.4
    

    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:

    - 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
  13. skshetry
    added a commit that references this issue on Jun 18, 2022

    gha: fix issue when caching virtual environments

    4f78c33
  14. panticmilos commented on Jun 22, 2022

    @panticmilos
    panticmilos
    on Jun 22, 2022
    Contributor
    More actions

    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

  15. olirice commented on Jun 22, 2022

    @olirice
    olirice
    on Jun 22, 2022
    Author
    More actions

    using the output of actions/setup-python@vX that includes the patch version in the cache key sounds great. Thank you for the help

  16. olirice
    closed this as completedon Jun 22, 2022
  17. chance2021 commented on Dec 16, 2022

    @chance2021
    chance2021
    on Dec 16, 2022
    More actions

    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)
    
  18. copybara-service
    added 2 commits that reference this issue on Dec 8, 2023

    Use full python version to avoid bad interpreter errors.

    b88209c

    Use full python version to avoid bad interpreter errors.

    5525ace
  19. markfickett commented on Sep 23, 2024

    @markfickett
    markfickett
    on Sep 23, 2024
    More actions

    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:

              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.

  20. v-HarithaVattikuti
    added a commit that references this issue on Jul 30, 2025

    Bump form-data to fix critical vulnerabilities #182 & #183 (#1163)

    fbeb884
  21. mitjohnson
    added a commit that references this issue on Apr 17, 2026

    chore(deps): update actions/setup-python action to v6 (#11)

    40bf217
  22. MateoGreil
    added a commit that references this issue on Jul 4, 2026

    ⬆️ Update actions/setup-python action to v6 (#21)

    282b9d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @panticmilos
    panticmilos

Labels

bugSomething isn't workingSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.