SoS Jupyter Notebook下R kernel无法运行问题求助
问题:SoS Jupyter Notebook中R Kernel无法运行,报错
cannot import name 'Sequence' from 'collections' - 普通Jupyter Notebook使用R kernel(
ir)无异常,但在SoS Notebook中执行任何R命令均报错 - 错误信息:
cannot import name 'Sequence' from 'collections' (/usr/lib/python3.10/collections/init.py)
- 控制台警告:
WARNING: Failed to locate subkernel R with kernel "ir" and language "R": cannot import name 'Sequence' from 'collections' (/usr/lib/python3.10/collections/init.py)
环境安装信息
$ jupyter kernelspec list Available kernels: bash /home/leoca/.local/share/jupyter/kernels/bash ir /home/leoca/.local/share/jupyter/kernels/ir octave /home/leoca/.local/share/jupyter/kernels/octave python3 /home/leoca/.local/share/jupyter/kernels/python3 sos /home/leoca/.local/share/jupyter/kernels/sos $ pip list | grep sos sos 0.23.4 sos-bash 0.20.0 sos-notebook 0.23.4 sos-r 0.19.6
解决方案
这个问题是Python 3.10版本的兼容性问题:Python 3.10将collections.Sequence迁移到了collections.abc模块,而你当前安装的sos-r版本(0.19.6)未适配这一变化。
优先升级sos-r到兼容版本
执行以下命令升级sos-r,新版本已修复Python 3.10的适配问题:pip install --upgrade sos-r临时兼容修复(无法升级时使用)
找到sos-r包中导入Sequence的Python文件,将原有导入代码:from collections import Sequence修改为兼容多版本的代码:
try: from collections.abc import Sequence except ImportError: from collections import Sequence
内容的提问来源于stack exchange,提问作者LEo
相关产品推荐
相关产品推荐

