Solution skill
ImportError: cannot import name 'MutableMapping' from 'collections'
Complete solution
Fixes ImportError: cannot import name 'MutableMapping' from 'collections' Use when Python 3.10+ and `from collections import [ABC]` Not for: Python < 3.10 (it works there, with a deprecation warning)
How to fix ImportError: cannot import name 'MutableMapping' from 'collections'
Python 3.10 removed the abstract base classes from the top-level collections module. Change from collections import MutableMapping to from collections.abc import MutableMapping. Same for Iterable, Mapping, Sequence, Callable. If it is a library doing this, upgrade the library; collections.abc has been the right home since Python 3.3.
The exact error
ImportError: cannot import name 'MutableMapping' from 'collections'Fix it
Find it:
grep -rn "from collections import" --include=*.py .. Expected: the offending linesChange to
from collections.abc import MutableMapping(etc.). Expected: works on 3.10+ and all the way back to 3.3Library-owned: upgrade the library. Expected: upstream fixed long ago
When this applies
Python 3.10+ and from collections import [ABC]
When this does NOT apply
Python < 3.10 (it works there, with a deprecation warning)
Versions
Python >= 3.10
Why it happens
The ABCs lived in collections.abc since 3.3; the 3.10 cleanup removed the aliases.
Edge cases
collections.abc has existed since 3.3, so the fix is back-compatible; no version guard needed.
Evidence
Asked about: ImportError: cannot import name 'MutableMapping' from 'collections' (gh:opencve/opencve#371). The verified fix: Python 3.10 removed the abstract base classes from the top-level collections module. Change from collections import MutableMapping to from collections.abc import MutableMapping. Same for Iterable, Mapping, Sequence, Callable. If it is a library doing this, upgrade the library; collections.abc has been the right home since Python 3.3. Full thread: https://github.com/opencve/opencve/issues/371
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
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_qNftJLkL2e2uUBlVNZ_BhQ" 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 'MutableMapping' from 'collections' <span>— Vectle</span></a>