001 ImportError: cannot import name ‘Iterable‘ from ‘collections‘

自 Python 3.10 开始,库 collections 以下各项都停用了,其中就包含了 pygal._compat.py 中的 from collections import Iterator

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

需要自己更改 Lib\site-packages\pygal_compat.py` 的内容

【直接复制代码即可修改】

#修改之前的出错代码行
# from collections import Iterable        

#修改为以下
try:
    from collections.abc import Iterable
except ImportError:
    from collections import Iterable

refer:

importerror cannot import name 'Iterable' from 'collections'-有问必答-CSDN问答

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
ImportError: cannot import name 'Iterable' from 'collections' 是一个常见的错误,在这个错误中,无法从collections模块中导入名为'Iterable'的内容。这个错误通常是由于Python版本的不兼容性引起的。 解决这个问题的一个方法是修改代码中导入Iterable的部分,将其更改为从collections.abc模块中导入。你可以尝试使用以下代码进行修改: ```python try: from collections.abc import Iterable except ImportError: from collections import Iterable ``` 通过这种方式,首先尝试从collections.abc模块中导入Iterable,如果导入失败则从collections模块中导入。这样可以兼容Python 2和Python 3之间的差异。 希望这个方法可以帮到你!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [001 ImportError: cannot import name ‘Iterable‘ from ‘collections](https://blog.csdn.net/qq_55285829/article/details/127577631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [安装pygal但是import pygal报错ImportError: cannot import name ‘Iterable‘ from ‘collections](https://blog.csdn.net/CatherineEDI/article/details/124973546)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值