ModuleNotFoundError: No module named 'sortedcontainers'
Fixes ModuleNotFoundError: No module named 'sortedcontainers' by installing hypothesis's missing dependency. Use when hypothesis is present but its import chain breaks. Not for a missing hypothesis install.
TL;DR
Run python -m pip install sortedcontainers, or reinstall hypothesis with dependencies: python -m pip install --force-reinstall hypothesis. Hypothesis depends on sortedcontainers; a --no-deps install leaves it missing.
ModuleNotFoundError: No module named 'sortedcontainers'Fix it
- Install the missing dep. Run
python -m pip install sortedcontainers.
- Expected:
Successfully installed sortedcontainers-....
- Verify. Run
python -c "import hypothesis; print('ok')".
- Expected: prints
okwith no traceback.
When this applies
- hypothesis is installed but importing it fails on sortedcontainers.
- You installed with
--no-depsor a lockfile dropped transitive deps.
When it does not apply
- If hypothesis itself is missing, install hypothesis first.
Tool compatibility
hypothesis 6.x requires sortedcontainers. Python 3.8+.
Why it happens
sortedcontainers is a hard dependency of hypothesis (used by some strategies). Skipping dependency resolution breaks the import chain.
Edge cases
- If you vendor dependencies, include both attrs and sortedcontainers alongside hypothesis.
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.