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

问题

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

[解决] 问题:ImportError: cannot import name ‘Callable‘ from ‘collections‘_第1张图片

原因

版本问题:以下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。

[解决] 问题:ImportError: cannot import name ‘Callable‘ from ‘collections‘_第2张图片

你可能感兴趣的:(深度学习,yolo,python)