我正在研究 FastAPI 并发生了这个错误。
from fastapi import FastAPI
import uvicorn
app = FastAPI()
@app.get("/ping")
async def ping():
return "Hello, I am alive"
if __name__ == "__main__":
uvicorn.run(app, host='localhost', port=8000)
Traceback (most recent call last):
File "D:/own_thesis/training/for_api.py", line 2, in <module>
from fastapi import FastAPI
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\fastapi\__init__.py", line 7, in <module>
from .applications import FastAPI as FastAPI
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\fastapi\applications.py", line 15, in <module>
from fastapi import routing
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\fastapi\routing.py", line 22, in <module>
from fastapi.datastructures import Default, DefaultPlaceholder
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\fastapi\datastructures.py", line 3, in <module>
from starlette.datastructures import URL as URL # noqa: F401
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\starlette\datastructures.py", line 7, in <module>
from starlette.concurrency import run_in_threadpool
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\starlette\concurrency.py", line 11, in <module>
from typing_extensions import ParamSpec
ImportError: cannot import name 'ParamSpec' from 'typing_extensions' (C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\typing_extensions.py)
只需将 @arunppsg 的回复作为一个带有小拼写错误更正的答案即可:您只需要运行
pip uninstall typing_extensions
pip uninstall fastapi
pip install --no-cache fastapi
问题就消失了。
小错别字更正在pip uninstall typing_extensions
(末尾有 s)。谢谢@arunppsg,我无法对你的评论发表评论,因为我仍然没有 50 点声誉,并决定将其作为答案。如果您将评论转换为答案,我们很乐意将其删除。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)