从typing_extensions导入参数规范导入错误:无法从'typing_extensions'导入名称'ParamSpec'



我正在使用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:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesfastapi__init__.py", line 7, in <module>
from .applications import FastAPI as FastAPI
File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesfastapiapplications.py", line 15, in <module>
from fastapi import routing
File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesfastapirouting.py", line 22, in <module>
from fastapi.datastructures import Default, DefaultPlaceholder
File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesfastapidatastructures.py", line 3, in <module>
from starlette.datastructures import URL as URL  # noqa: F401
File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesstarlettedatastructures.py", line 7, in <module>
from starlette.concurrency import run_in_threadpool
File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesstarletteconcurrency.py", line 11, in <module>
from typing_extensions import ParamSpec
ImportError: cannot import name 'ParamSpec' from 'typing_extensions' (C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagestyping_extensions.py)

只是让@arunppsg的响应成为一个带有小错别字更正的答案:您只需要运行

pip uninstall typing_extensions
pip uninstall fastapi
pip install --no-cache fastapi

,问题就消失了。

小的错别字更正是在pip uninstall typing_extensions中(以s结尾)。谢谢@arunppsg,我不能评论你的评论,因为我还没有50分的声望,所以决定把它作为一个答案。如果你把你的评论转换成一个答案,我们很乐意删除它。

最新更新