使用gradio启动web-ui时出现cannot import name 'RootModel' from 'pydantic'

使用gradio启动web-ui时出现cannot import name 'RootModel' from 'pydantic'

出现该报错的原因:pydantic版本与gradio版本不对应。

例:我使用的pydantic版本为1.10.14,报错时gradio的版本是最新版4.19.2。

找到gradio github源码中的requirements.txt:

aiofiles>=22.0,<24.0
altair>=4.2.0,<6.0
fastapi
ffmpy
gradio_client==0.10.1
httpx>=0.24.1
huggingface_hub>=0.19.3
importlib_resources>=1.3,<7.0
Jinja2<4.0
markupsafe~=2.0
matplotlib~=3.0
numpy~=1.0
orjson~=3.0
packaging
pandas>=1.0,<3.0
pillow>=8.0,<11.0
pydantic>=2.0
python-multipart>=0.0.9  # required for fastapi forms
pydub
pyyaml>=5.0,<7.0
semantic_version~=2.0
typing_extensions~=4.0
uvicorn>=0.14.0
typer[all]>=0.9,<1.0
tomlkit==0.12.0
ruff>=0.2.2

可以看到其要求的pydantic版本要大于等于2.0。

而我其他的包依赖的pydantic版本是1.x,因此我选择将gradio包的版本降低为3.48.0,问题解决。

posted @ 2024-03-04 10:45  一蓑烟雨度平生  阅读(1254)  评论(0编辑  收藏  举报