[Python] Python FastAPI package python-multipart installed but not found

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem with FastAPI, it is not recognizing the package python-multipart, which I need for Form type objects. I am using pycharm. I tried installing the package (pip install python-multipart) but FastAPI can't find it even after installing it. Any Ideas on how I could proceed to fix this issue? I tried looking for answers in the internet but they didn't help unfortunately. This is the stack trace:

    (venv) C:\Users\r\Documents\AI\Code-That-ReactStableDiffusion\api>uvicorn api:app --reload
    ←[32mINFO←[0m: Will watch for changes in these directories: ['C:\\Users\\r\\Documents\\AI\\Code-That-ReactStableDiffusion\\api']
    ←[32mINFO←[0m: Uvicorn running on ←[1mhttp://127.0.0.1:8000←[0m (Press CTRL+C to quit)
    ←[32mINFO←[0m: Started reloader process [←[36m←[1m1888←[0m] using ←[36m←[1mStatReload←[0m
    safety_checker\model.safetensors not found
    C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\transformers\models\clip\feature_extraction_clip.py:28: FutureWarning: The class CLIPFeatureExtractor is depreca
    ted and will be removed in version 5 of Transformers. Please use CLIPImageProcessor instead.
    warnings.warn(
    `text_config_dict` is provided which will be used to initialize `CLIPTextConfig`. The value `text_config["id2label"]` will be overriden.
    Form data requires "python-multipart" to be installed.
    You can install "python-multipart" with:

    pip install python-multipart

    Process SpawnProcess-1:
    Traceback (most recent call last):
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
    self.run()
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
    ^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
    ^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\server.py", line 68, in serve
    config.load()
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\config.py", line 473, in load
    self.loaded_app = import_from_string(self.app)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\uvicorn\importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 940, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "C:\Users\r\Documents\AI\Code-That-ReactStableDiffusion\api\api.py", line 39, in <module>
    @app.post("/generate_with_image")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 706, in decorator
    self.add_api_route(
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 645, in add_api_route
    route = route_class(
    ^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\routing.py", line 497, in __init__
    self.body_field = get_body_field(dependant=self.dependant, name=self.unique_id)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\dependencies\utils.py", line 801, in get_body_field
    check_file_field(final_field)
    File "C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages\fastapi\dependencies\utils.py", line 100, in check_file_field
    raise RuntimeError(multipart_not_installed_error) from None
    RuntimeError: Form data requires "python-multipart" to be installed.
    You can install "python-multipart" with:

    pip install python-multipart

    Continue reading...

Compartilhe esta Página