RuntimeError: Form data requires "python-multipart" to be installed. #5144
-
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 13 replies
-
|
When iam running from global terminal this python package work :) can you guys fix this for vs code? |
Beta Was this translation helpful? Give feedback.
-
|
If you install both you will have problems because they conflict, they expose the same name. Uninstall |
Beta Was this translation helpful? Give feedback.
-
|
My envirement: (venv) ~/item/api-server python
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(venv) ~/item/api-server pip -V
pip 23.3.1 from /Users/alan/item/api-server/venv/lib/python3.11/site-packages/pip (python 3.11)
(venv) ~/item/api-server whereis uvicorn
uvicorn: /Users/alan/item/api-server/venv/bin/uvicorn
(venv) ~/item/api-server
For me, I confirmed that the virtual environment was turned on But: Details(venv) ~/item/api-server uvicorn main:app --reload pip install python-multipart Process SpawnProcess-1: pip install python-multipart I was confused and until finally remembered It worked successfully! I don't know why Test codefrom fastapi import FastAPI, File, UploadFile # noqa
from fastapi import APIRouter
from fastapi.staticfiles import StaticFiles
app = FastAPI(debug=True)
app.mount('/', StaticFiles(directory='./static'), name='/')
file = APIRouter(prefix='/file', tags=['fileOper'])
@file.post('/upload')
def create_file(file: bytes = File()):
return dict(code=200, msg='', data=dict(length=len(file)))
@app.get('/')
def index():
return {"message": "Hello World"}
app.include_router(file) |
Beta Was this translation helpful? Give feedback.
-
|
I encountered same issue, and the problem was caused by conda environment. I've been using both PyCharm and Conda, and that's what caused the promblem. |
Beta Was this translation helpful? Give feedback.
-
|
I have a similar issue. FastAPI can not detect python-multipart package. ❯ python -V
Python 3.12.2
❯ pip freeze | grep fastapi
fastapi==0.115.3
❯ pip freeze | grep multipart
python-multipart==0.0.14As you see, I have python-multipart installed on my environment, but still fastapi can't detect it. That's because python-multipart is no more imported via multipart package (from version from multipart.multipart import parse_options_headerI've got same ImportError if I import package this way. From version 0.0.14 package should be imported via python_multipart >>> from multipart.multipart import parse_options_header
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'multipart'
>>> from python_multipart.multipart import parse_options_header
>>> assert parse_options_headerCan you pls fix this import? P.S. as hotfix I can install ❯ pip freeze | grep multipart
python-multipart==0.0.12
❯ python -q
>>> from multipart.multipart import parse_options_header
>>> assert parse_options_header |
Beta Was this translation helpful? Give feedback.
-
|
I also faced the same issue. I used Conda env and Pycharm. I did everything mentioned here, but it didn't work. Even when I activated the virtual environment, it pointed out the error to a folder in the C drive. So I installed But I can not figure out the problem. |
Beta Was this translation helpful? Give feedback.




If you install both you will have problems because they conflict, they expose the same name. Uninstall
multipartand only keeppython-multipart.