tiangolo/fastapi · error · RuntimeError
Form data requires "python-multipart" to be installed. It…
Error message
Form data requires "python-multipart" to be installed. It seems you installed "multipart" instead. You can remove "multipart" with: pip uninstall multipart And then install "python-multipart" with: pip install python-multipart
What it means
RuntimeError raised by ensure_multipart_is_installed when the wrong package is present: `from python_multipart import __version__` failed (or version is too old) but `from multipart import __version__` succeeded, and then `from multipart.multipart import parse_options_header` failed with ImportError. The `multipart` package on PyPI is a different, incompatible library from `python-multipart`, which is what FastAPI/Starlette need to parse form/multipart bodies.
Solutions
- Uninstall the wrong package and install the right one: pip uninstall multipart && pip install python-multipart.
- Add python-multipart (not multipart) to requirements.txt / pyproject dependencies.
- Install fastapi[standard], which already pulls python-multipart.
- After fixing, verify with: python -c "import python_multipart; print(python_multipart.__version__)".
Example fix
# before pip install multipart # wrong package # -> RuntimeError: It seems you installed "multipart" instead. # after pip uninstall multipart pip install python-multipart
Defensive patterns
Strategy: fallback
Validate before calling
# Verify the correct package is importable before using Form/File
import importlib.util, sys
if importlib.util.find_spec("python_multipart") is None:
print("python-multipart missing or wrong 'multipart' installed")
sys.exit(1)
# also guard against the wrong package shadowing the right one
import importlib
try:
importlib.import_module("multipart.multipart") # parse_options_header lives here
except ImportError:
print("the wrong 'multipart' package is installed; install python-multipart")
sys.exit(1) Try / catch
try:
from python_multipart import __version__
assert __version__ > "0.0.12"
except (ImportError, AssertionError):
# fallback: refuse to start Form/File routes, or instruct install
raise RuntimeError("pip install python-multipart") Prevention
- Always install python-multipart, never the bare `multipart` package.
- Pin python-multipart in requirements.txt / pyproject explicitly.
- Prefer fastapi[standard] so the correct parser is pulled in transitively.
- After dependency changes, verify `import python_multipart` succeeds before deploying.
When it happens
Trigger: An endpoint or dependency uses Form() or File() (multipart parsing), so FastAPI calls ensure_multipart_is_installed(), but the environment has `multipart` installed instead of `python-multipart`.
Common situations: A developer ran `pip install multipart` (wrong package, same import name) instead of `pip install python-multipart`; a transitive dependency pulled in the bare `multipart` package; an old requirements file with the wrong name; fastapi[standard] not installed and the correct package missing.
Related errors
- Form data requires "python-multipart" to be installed. You…
- To use the fastapi command, please install…
- Expected UploadFile, received
- No Jessica token provided
- X-Key header invalid
AI-assisted analysis of tiangolo/fastapi@3e8d1526d8 (2026-08-11).
Data as JSON: /api/errors/93df0e4177ef02d2.
Report an issue: GitHub.
Appendix: source
Thrown at fastapi/dependencies/utils.py:126
assert __version__ > "0.0.12"
except (ImportError, AssertionError):
try:
# __version__ is available in both multiparts, and can be mocked
from multipart import ( # type: ignore[no-redef,import-untyped]
__version__,
)
assert __version__
try:
# parse_options_header is only available in the right multipart
from multipart.multipart import ( # type: ignore[import-untyped]
parse_options_header,
)
assert parse_options_header
except ImportError:
logger.error(multipart_incorrect_install_error)
raise RuntimeError(multipart_incorrect_install_error) from None
except ImportError:
logger.error(multipart_not_installed_error)
raise RuntimeError(multipart_not_installed_error) from None
def get_parameterless_sub_dependant(*, depends: params.Depends, path: str) -> Dependant:
assert callable(depends.dependency), (
"A parameter-less dependency must have a callable dependency"
)
own_oauth_scopes: list[str] = []
if isinstance(depends, params.Security) and depends.scopes:
own_oauth_scopes.extend(depends.scopes)
return get_dependant(
path=path,
call=depends.dependency,
scope=depends.scope,
own_oauth_scopes=own_oauth_scopes,
)View on GitHub (pinned to 3e8d1526d8)