Solution skill
ImportError: cannot import name 'cached_path' from 'transformers.file_utils'
Complete solution
Fixes ImportError: cannot import name 'cached_path' from 'transformers.file_utils' Use when importing a transformers-based library fails on `from transformers.file_utils import cached_path` Not for: you import cached_path in your own code (just import it from huggingface_hub instead)
How to fix ImportError: cannot import name 'cachedpath' from 'transformers.fileutils'
A library you use (txtai, classy-classification, etc.) imports cached_path from its old home and your transformers is too new. Upgrade that library; if it has no fixed release, pin transformers<=4.21.3. cached_path was removed from transformers.fileutils (it lives in huggingfacehub now) in late 2022.
The exact error
ImportError: cannot import name 'cached_path' from 'transformers.file_utils'Fix it
Read the traceback to find the importing library (the frame above transformers). Expected: e.g. txtai, classy_classification
Upgrade it:
pip install -U [library]. Expected: the new release imports from the new locationIf no fixed release exists:
pip install "transformers<=4.21.3". Expected: import works again
When this applies
importing a transformers-based library fails on from transformers.file_utils import cached_path
When this does NOT apply
you import cachedpath in your own code (just import it from huggingfacehub instead)
Versions
transformers >= 4.22 with libs importing the old path
Why it happens
transformers removed fileutils.cachedpath; the canonical home is now huggingface_hub.
Edge cases
Pinning transformers back is temporary; the library will break again on other new-transformers changes.
Evidence
Asked about: ImportError: cannot import name 'cachedpath' from 'transformers.fileutils' (gh:pandora-intelligence/classy-classification#24). The verified fix: A library you use (txtai, classy-classification, etc.) imports cached_path from its old home and your transformers is too new. Upgrade that library; if it has no fixed release, pin transformers<=4.21.3. cached_path was removed from transformers.fileutils (it lives in huggingfacehub now) in late 2022. Full thread: https://github.com/pandora-intelligence/classy-classification/issues/24
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_vpP05teT0hQg8gmAgULbNg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import name 'cached_path' from 'transformers.file_utils' <span>— Vectle</span></a>