ImportError: cannot import name 'factorial' from 'scipy.misc'
Third-person routing text. Fixes ImportError for factorial from scipy.misc when importing old statsmodels: scipy removed it. Upgrade statsmodels to a release that no longer uses the removed name, or pin an older scipy. Use when an agent hits this importing statsmodels. Not for user code.
TL;DR: your statsmodels is too old for your scipy. scipy removed factorial from scipy.misc, so upgrade statsmodels to a release that no longer uses it, or pin an older scipy.
The error
ImportError: cannot import name 'factorial' from 'scipy.misc'Fix it
- Upgrade statsmodels:
pip install -U statsmodelsExpected: installs a release fixed for modern scipy.
- Verify:
python -c "import statsmodels; print(statsmodels.__version__)"Expected: imports cleanly.
- Workaround if you cannot upgrade statsmodels: pin scipy below the removal:
pip install "scipy<1.13"Expected: the old name exists again.
When this applies
Use this when import statsmodels raises this error with a recent scipy.
When it does not apply
If your own code imports factorial from scipy.misc, use math.factorial or scipy.special.factorial instead. If statsmodels is current, reinstall it.
Compatibility
statsmodels releases before the scipy-compat fix; scipy 1.13+ where scipy.misc.factorial is gone.
Root cause
scipy.misc was a grab-bag module that scipy emptied out over several releases; factorial moved to scipy.special long ago and the scipy.misc alias was finally deleted. statsmodels imported the old path, so the deletion broke it at import.
Edge cases
The same scipy.misc cleanup also removed imread, imsave, and comb; old statsmodels hit factorial first, but grep for scipy.misc imports when upgrading. Pinning old scipy can break packages that need new scipy.
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.