ImportError: No module named decorator
Third-person routing text. Fixes networkx failing with No module named decorator: networkx requires the decorator package. pip install decorator fixes it. Use when an agent hits this importing networkx. Not for other missing modules.
TL;DR: networkx requires the decorator package and it is not installed. Run pip install decorator and networkx imports fine.
The error
ImportError: No module named decoratorFix it
- Install decorator:
pip install decoratorExpected: install completes.
- Verify:
python -c "import networkx; print(networkx.__version__)"Expected: prints the version, no error.
When this applies
Use this when import networkx raises the decorator error, common after --no-deps installs.
When it does not apply
If decorator is installed but networkx still fails, check for a broken install with pip check. If the error names a different module, install that one instead.
Compatibility
All networkx 2.x versions; decorator has always been required.
Root cause
networkx uses the decorator package for its decorator-heavy API (notable edge-attribute decorators). The dependency is declared, but installs that skip dependencies leave it out.
Edge cases
Very old decorator versions can break new networkx; installing normally gets a compatible one. In conda envs, install decorator from the same channel as networkx.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.