我的 FastAPI 有问题,它无法识别 Forms 所需的 python-multipart 包。我正在使用pycharm。我尝试安装该软件包(pip install python-multipart),但即使安装后 Fastapi 也找不到它。关于如何解决这个问题有什么想法吗? 我尝试在互联网上寻找答案,但不幸的是它们没有帮助。 这是堆栈跟踪:
(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
在shell中,尝试
import multipart
,如果有效,我实际上不知道如何解决这个问题,如果它生成错误ModuleNotFoundError
,尝试$ pip install python-multipart target="C:\Users\r\AppData\Local\Programs\Python\Python311\Lib\site-packages"