[解决] 问题:ImportError: cannot import name ‘Callable‘ from ‘collections‘

问题

我在运行yolov8的代码时,出现了ImportError: cannot import name 'Callable' from 'collections'的错误

原因

版本问题:以下collections的方法都在Python3.10版本后被取消了

 ["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"]

解决

”from collections import ***“,在3.6版本之前collections后面是不需要带.abc的,3.7之后就会提醒需要加.abc,现在3.10版本停止使用不加.abc的情况。

所以正确的写法应该是“from collections.abc import ***",根据上图的错误提示,红框内需要修改添加.abc。

猜你喜欢

转载自blog.csdn.net/weixin_45662399/article/details/134501374