Skip to content

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

Open
@EpicWink

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions