from typing import Tuple, Literal
ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)

理由:因为 Literal 类型提示是在 Python 3.8 中引入的。在 Python 3.7 中,Literal 并不存在于 typing 模块中,所以会出现 ImportError 错误

解决一:升级python

解决二:换为from typing_extensions import Literal

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐