python 3.1 以上版本报错 ImportError: cannot import name ‘Iterable‘ from ‘collections‘

自 Python 3.10 開始,庫 collections 以下各項都停用了

["Awaitable", "Coroutine", "AsyncIterable", "AsyncIterator", "AsyncGenerator", "Hashable", "Iterable", "Iterator", "Generator", "Reversible", "Sized", "Container", "Callable", "Collection", "Set", "MutableSet", "Mapping", "MutableMapping", "MappingView", "KeysView", "ItemsView", "ValuesView", "Sequence", "MutableSequence", "ByteString"]

因此,必須自己更改 对应 的內容

已 hyper 为示例

python 3.1 以上版本报错 ImportError: cannot import name ‘Iterable‘ from ‘collections‘_第1张图片

 python 3.1 以上版本报错 ImportError: cannot import name ‘Iterable‘ from ‘collections‘_第2张图片

 在对应文件   引入模型 collections 后面加入 .abc 即可

from collections import Iterable, Mapping 
中修改
from collections.abc import Iterable, Mapping

python 3.1 以上版本报错 ImportError: cannot import name ‘Iterable‘ from ‘collections‘_第3张图片 

 

你可能感兴趣的:(python)