ModuleNotFoundError: No module named 'multipart'
Fixes ModuleNotFoundError: No module named 'multipart' Use when FastAPI/Starlette app using UploadFile, File(...) or Form(...) raises No module named 'multipart' Not for: you are not doing file uploads (then you do not need it at all)
How to fix ModuleNotFoundError: No module named 'multipart'
FastAPI needs the separate python-multipart package for File/Form uploads but does not install it. Run python -m pip install python-multipart and add it to requirements.txt. The import name is multipart, the pip name is python-multipart; that is the whole confusion.
The exact error
ModuleNotFoundError: No module named 'multipart'Fix it
python -m pip install python-multipart
Expected: Successfully installed python-multipart
python -c "import multipart"
Expected: no error
- Add
python-multipartto requirements.txt and redeploy.
Expected: uploads work in the deployed env too
When this applies
FastAPI/Starlette app using UploadFile, File(...) or Form(...) raises No module named 'multipart'
When this does NOT apply
you are not doing file uploads (then you do not need it at all)
Versions
FastAPI file uploads / Form data
Why it happens
multipart parsing is an optional dependency; FastAPI raises at request time, not import time.
Edge cases
python-multipart 0.0.18+ changed some internals; if an old pin breaks, unpin it.
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.