ImportError: cannot import name 'OrderedDict' from 'typing' (C:\Users\3636\anaconda3\envs\pytorch_cpu\lib\typing.py)
时间: 2023-07-08 11:54:33 浏览: 41
这个错误信息表示在你的代码中,使用了 `typing` 模块下的 `OrderedDict`,但是该模块中并没有 `OrderedDict` 这个类。可能的原因是你的 Python 版本过低,或者你引用了其他模块中的 `typing` 库,导致版本不兼容。解决办法是升级 Python 版本,或者使用 `collections` 库中的 `OrderedDict`。例如:
```python
from collections import OrderedDict
```
这样就可以避免这个错误了。
相关问题
ImportError: cannot import name 'OrderedDict' from 'typing' (E:\Anaconda\envs\pytorch\lib\typing.py)
这个错误是因为在当前环境下的 typing 模块中找不到 OrderedDict 类。在 Python 3.7 及更高版本中,OrderedDict 类已经从 typing 模块移到了 collections 模块中。你可以尝试使用以下代码解决这个问题:
```python
from collections import OrderedDict
```
这样就可以正确导入 OrderedDict 类了。如果仍然遇到问题,请确保你的 Python 版本是 3.7 或更高,并检查是否有其他导入冲突或命名问题。
ImportError: cannot import name 'OrderedDict' from 'typing' (C:\Users\ldz\.conda\envs\pytorch_gpu\lib\typing.py)
这个错误通常是由于使用了过期的代码或版本不匹配引起的。在最新的 Python 版本中,`OrderedDict` 被移动到了 `collections` 模块中,您可以按照以下方式进行导入:
```python
from collections import OrderedDict
```
如果您使用的是较旧的 Python 版本,可以尝试更新您的 Python 版本或使用以下导入语句:
```python
from typing import OrderedDict
```
请确保您的 Python 版本与代码所使用的库和模块版本兼容。