报错 ImportError: cannot import name ‘Sequence‘ from ‘collections‘

环境:python3.10

问题:

File "G:\research\code\MicroDE_py\plot_bcic_iv_4_ecog_trial.py", line 262, in <module>
    from skorch.helper import predefined_split
  File "C:\Users\Lenovo\.conda\envs\braindecode\lib\site-packages\skorch\helper.py", line 6, in <module>
    from collections import Sequence
ImportError: cannot import name 'Sequence' from 'collections' (C:\Users\Lenovo\.conda\envs\braindecode\lib\collections\__init__.py)

解决:

将报错的代码句子:

from collections import Sequence

修改为:

from collections.abc import Sequence

程序可以成功运行。

原理:

Sequence should be imported from collections.abc instead of collections since Python 3.3. A warning is printed starting with Python 3.7 and in Python 3.9 the new import location will be required.

This PR imports from collections.abc while still falling back to importing from collections for older Python versions.

翻译:

Sequence应该从Python 3.3 开始collections.abc而不是从collections开始导入。从 Python 3.7 开始打印警告,在 Python 3.9 中将需要新的导入位置。

此 PR 导入自,collections.abc同时仍回退到从collections旧 Python 版本导入。

参考:

import Sequence from collections.abc to suppress warning in python 3.… by brian-from-quantrocket · Pull Request #737 · wireservice/agate · GitHub

  • 9
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值