ImportError: cannot import name 'TypedDict' from 'typing'
时间: 2023-09-22 07:10:59 浏览: 132
这个错误通常表示你使用的 Python 版本过于陈旧,或者是 typing 模块版本过低。请确保你使用的 Python 版本高于 3.8,并且 typing 模块版本大于等于 3.8。
如果你的 Python 版本已经满足要求,但仍然出现这个错误,你可以尝试更新 typing 模块。在终端中执行以下命令:
```
pip install -U typing
```
如果你使用的是 Python 3.7 及以下版本,则无法使用 TypedDict 类型注解。你可以考虑使用字典类型(Dict)或者自定义一个类来代替 TypedDict。
相关问题
ImportError: cannot import name TypedDict from typing (/opt/module/miniconda3/envs/superset/lib/python3.7/typing.py)
这个错误通常出现在 Python3.7 以下版本中,因为 `typing.TypedDict` 是在 Python3.7 中引入的。如果你的 Python 版本低于 3.7,则需要升级到 Python3.7 或更高版本才能使用 `TypedDict`。如果你不能升级 Python 版本,你可以考虑使用第三方库 `typing_extensions` 中的 `TypedDict`。你可以通过执行以下命令来安装 `typing_extensions`:
```
pip install typing_extensions
```
然后,在你的代码中导入 `TypedDict` 时,使用以下语句:
```
from typing_extensions import TypedDict
```
superset db upgrade 报错 ImportError: cannot import name TypedDict from typing (/home/owen/.conda/envs/superset/lib/python3.7/typing.py)
这个错误通常是由于 Python 版本过低导致的,因为 `typing.TypedDict` 是在 Python 3.8 中引入的新特性。你可以尝试更新你的 Python 版本到 3.8 或以上版本来解决这个问题。
如果你无法更新 Python 版本,也可以尝试安装 `typing_extensions` 库并使用其中的 `TypedDict` 类来代替 `typing.TypedDict`。你可以使用以下命令进行安装:
```
pip install typing-extensions
```
然后在你的代码中这样导入 `TypedDict`:
```
from typing_extensions import TypedDict
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)