Skip to content

pip-compile errors when generating hashes with AttributeError 'cache_clear' with pip v25.1 #2176

Closed

Description

@EpicWink

When running with pip v25.1, pip-compile --generate-hashes fails with exception:

AttributeError: 'function' object has no attribute 'cache_clear'

Environment Versions

  1. OS Type: Linux - Ubuntu 22.04.5 LTS (Jammy Jellyfish)
  2. Python version: 3.10.12
  3. pip version: 25.1
  4. pip-tools version: 7.4.1

Steps to replicate

# requirements.in
numpy
pip install -U 'pip >= 25.1'
pip-compile --generate-hashes

Expected result

Successful lock file generation

Actual result

Exception: AttributeError: 'function' object has no attribute 'cache_clear'

Traceback (click to expand)
Traceback (most recent call last):
  File "./venv/bin/pip-compile", line 8, in <module>
    sys.exit(cli())
  File "./venv/lib/python3.10/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  File "./venv/lib/python3.10/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "./venv/lib/python3.10/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "./venv/lib/python3.10/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "./venv/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "./venv/lib/python3.10/site-packages/piptools/scripts/compile.py", line 471, in cli
    hashes = resolver.resolve_hashes(results) if generate_hashes else None
  File "./venv/lib/python3.10/site-packages/piptools/resolver.py", line 167, in resolve_hashes
    with self.repository.allow_all_wheels(), log.indentation():
  File "/usr/lib/python3.10/contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "./venv/lib/python3.10/site-packages/piptools/repositories/pypi.py", line 452, in allow_all_wheels
    self.finder.find_all_candidates.cache_clear()
AttributeError: 'function' object has no attribute 'cache_clear'

Additional notes

Caused by pypa/pip#13306 - you may want to catch AttributeError when running finder.find_all_candidates.cache_clear(), then attempt to run finder._all_candidates.clear()

Workaround

Use pip v25.0 or lower

pip install 'pip < 25.1'

Activity

  1. ericscales commented on Apr 27, 2025

    @ericscales

    Running into this as well.

  2. gkreitz commented on Apr 29, 2025

    @gkreitz
    Contributor

    pypa/pip@24f4600 seems to be the pip commit that broke this. It replaces @lru_cache with a custom cache that can no longer be cleared (afaict).

    It seems to me like a potential route to fix this would be to re-build the finder object instead of trying to clear the cache on it. I.e., replace self.finder.find_all_candidates.cache_clear() with self._finder = self.command._build_package_finder(...).

    I'm not sufficiently familiar with pip/pip-tools internals to know if that's a bad idea for other reasons (it's unclear to me how much state lies in the finder object, beyond the cache).

  3. cesarcoatl commented on May 1, 2025

    @cesarcoatl

    Has anyone considered using uv pip compile?

    I just tried it in one of my projects and it worked without issues.

  4. added a commit that references this issue on May 1, 2025
  5. 30 remaining items

  6. added a commit that references this issue on Jun 21, 2025
  7. marked Fails with 3.13.4 #2193 as a duplicate of this issue on Jun 23, 2025
  8. taleinat commented on Jul 3, 2025

    @taleinat

    Looking at a recent CI test run, it seems that this issue is what causes at least some of the tests to fail:
    https://github.com/jazzband/pip-tools/actions/runs/16041294513/job/45263254425#step:10:5449

  9. sirosen commented on Jul 3, 2025

    @sirosen
    Contributor

    That "Cron" workflow has been busted for a while and is misleading (sorry!). I'd advise anyone looking at pip-tools CI to ignore it for now; I haven't decided yet if I want to try to fix it or just remove it to replace later.
    CI runs triggered by commits for main should be stable right now -- we aren't testing against the newer pip versions in that workflow, so that builds are more reproducible.

    We have a contribution which fixes this particular issue (#2178), and I've taken that work and rebased it as part of #2195, but I unfortunately got stuck on some Windows path shenanigans and haven't got that cleaned up yet. The new tests ended up exploring some subtle and slightly weird behavior in pip internals (which is not user-facing in pip, but which pip-compile is exposing 😢 ).

    I consider support for the latest pip version the main issue which prevents me from wanting to push out a release, so if I can get #2195 across the finish line, we can incorporate some final fixes and hopefully have this issue fixed. Huge thanks to everyone who has chipped in on this effort, by the way!

  10. taleinat commented on Jul 3, 2025

    @taleinat

    Thanks for the info, the update and your work on this @sirosen!!

  11. EpicWink commented on Jul 14, 2025

    @EpicWink
    ContributorAuthor

    @sirosen @webknjaz I've successfully tested 757e62f (which includes #2195), verifying this is issue fixed

  12. webknjaz commented on Jul 14, 2025

    @webknjaz
    Member

    @EpicWink thanks for verifying!

  13. udaya2899 commented on Jul 24, 2025

    @udaya2899

    Our renovatebot setup with pip-compile manager is broken because of this with the same error. Seems it uses pip-tools 7.4.1 (from March 2024). Can you please create a new release with the fix?

  14. sirosen commented on Jul 24, 2025

    @sirosen
    Contributor

    We're actively working on it.

    I haven't had much time for FOSS work this week, but we're getting the changelog cleaned up so that we can push a release.

    I'm not sure what the best way is to communicate this publicly, but we are getting asked in multiple threads about this. We're well aware that a release is needed; there's only one thing left in the 7.5.0 milestone.

  15. webknjaz commented on Jul 31, 2025

    @webknjaz
    Member
  16. unpinned this issue on Jul 31, 2025
  17. added a commit that references this issue on Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions