Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python FastAPI package python-multipart installed but not found

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
like image 579
Rezarak SL Avatar asked Jun 22 '26 07:06

Rezarak SL


2 Answers

I had this problem with python-multipart 0.0.13 and 0.0.14 (both versions are Yanked - https://pypi.org/project/python-multipart/#history).

python-multipart 0.0.12 fixed this problem.

like image 53
TitanFighter Avatar answered Jun 24 '26 21:06

TitanFighter


Looks like an issue with Python's virtual environemnt: The terminal operates in (venv) environment, but the stack trace points to .../AppData/Local.

I would try the following:

  1. Activate virtual environment (Windows: <venv>\Scripts\activate.bat)
  2. Install dependencies (e.g. pip install python-multipart)
  3. Run your app

More infos about Python's VirtualEnvs: https://docs.python.org/3/library/venv.html

Let me know if this helps ;)

like image 22
Konstantin A. Magg Avatar answered Jun 24 '26 20:06

Konstantin A. Magg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!