Whoosh 2.7.4
(last released in 2016) does not run on Python 3.10 and newer. You get errors
like ImportError: cannot import name 'Iterable' from 'collections'
or ModuleNotFoundError: No module named 'imp'. The fix is a
drop-in replacement:
pip uninstall -y whoosh whoosh-reloaded
pip install whoosh3
Your import whoosh statements, your code, and your existing
on-disk indexes all keep working — whoosh3 keeps the same
import name and API and is tested on Python 3.10–3.14.
The errors you are probably seeing
If you just upgraded Python (or deployed to a newer runtime) and your search code stopped working, the traceback most likely ends with one of these:
ImportError: cannot import name 'Iterable' from 'collections'
ImportError: cannot import name 'Mapping' from 'collections'
ModuleNotFoundError: No module named 'imp'
AttributeError: module 'inspect' has no attribute 'getargspec'
These are not bugs in your code. They are the symptoms of a library that was written for an older Python and never updated for the changes that landed in Python 3.10, 3.12, and beyond.
Why it happens
Two long-planned removals in CPython are the usual culprits:
- ABCs moved out of
collections. Abstract base classes such asIterable,MappingandSequenceused to be importable straight fromcollections. That shortcut was deprecated back in Python 3.3 and removed in Python 3.10; they now live only incollections.abc. Any library still doingfrom collections import Iterablebreaks the moment it is imported on 3.10+. - The
impmodule was removed.impwas deprecated for years in favour ofimportliband was removed in Python 3.12. Code that reaches for it raisesModuleNotFoundError: No module named 'imp'.
The original Whoosh 2.7.4 predates all of this, and it is no longer being patched, so it simply does not import on current interpreters.
The fix
The maintained continuation of Whoosh is published on PyPI as
whoosh3. It fixes
the imports (they now come from collections.abc), drops
imp, and is tested in CI on CPython 3.10 through 3.14
and on PyPy. Crucially, it keeps the import name whoosh,
so nothing in your source has to change.
# remove whichever old package you have
pip uninstall -y whoosh whoosh-reloaded
# install the maintained continuation
pip install whoosh3
Then your existing code runs unchanged:
from whoosh.index import create_in
from whoosh.fields import Schema, TEXT, ID
from whoosh.qparser import QueryParser
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
ix = create_in("indexdir", schema)
writer = ix.writer()
writer.add_document(title="First doc", path="/a", content="hello whoosh")
writer.commit()
with ix.searcher() as s:
q = QueryParser("content", ix.schema).parse("whoosh")
for hit in s.search(q):
print(hit["title"])
Do I have to rebuild my index?
No. The on-disk index format is unchanged, so indexes written by older
Whoosh open fine under whoosh3. The whole point of the continuation
is that it is a maintenance fork, not a rewrite: same import name, same public
API, same file format — just running on modern Python.
Which package is which?
| PyPI package | Import name | Status |
|---|---|---|
whoosh (2.7.4) | whoosh | Original, last release 2016 — breaks on Python 3.10+ |
whoosh-reloaded | whoosh | Community fork, now inactive |
whoosh3 | whoosh | Actively maintained, Python 3.10–3.14 |
All three install under the whoosh import name, so only one can
be installed at a time. If you are unsure what you have, run
pip show whoosh whoosh3 whoosh-reloaded and uninstall everything
except whoosh3.
Still stuck?
If pip install whoosh3 does not resolve your traceback, that is
a bug I want to know about. Open an issue with your Python version and the full
traceback on the
issue tracker
and I will take a look.
The one-line fix:
pip install whoosh3
Prefer to see it work first? Run a real search index live in your browser (no install). If this saved you some debugging, a star on GitHub helps other people find the maintained version.
See also: Is Whoosh still maintained? · Full-text search in Flask · Full-text search in Django.