ModuleNotFoundError: No module named 'mpmath'
Third-person routing text. Fixes sympy failing with No module named mpmath: mpmath is a required dependency that is missing. pip install mpmath fixes it. Use when an agent hits this importing sympy. Not for other missing modules.
TL;DR: sympy requires the mpmath package and it is not installed. Run pip install mpmath and sympy imports fine.
The error
ModuleNotFoundError: No module named 'mpmath'Fix it
Install mpmath:
pip install mpmathExpected: install completes.
Verify:
python -c "import sympy; print(sympy.__version__)"Expected: prints the version, no error.
When this applies
Use this when import sympy raises the mpmath error, common in minimal installs and browser-based environments that assemble dependencies by hand.
When it does not apply
If mpmath is installed but sympy still fails, check you are in the right environment. If the error names a different module, install that one instead.
Compatibility
All sympy versions; mpmath has always been the required math backend.
Root cause
sympy does arbitrary-precision arithmetic through mpmath rather than reimplementing it. The dependency is declared, but hand-assembled or --no-deps installs can leave it out.
Edge cases
Some packagers split sympy into subpackages; make sure the mpmath requirement of the exact sympy build is satisfied. In locked environments, add mpmath next to sympy in the requirements file.