Ubuntu 20.04升级至22.04后启动报错:无法从colections导入interable
解决Ubuntu 22.04升级后启动报错:cannot import name 'interable' from 'colections'
这个错误是拼写错误导致的:正确的模块名是collections(不是colections),正确的导入对象是Iterable(首字母大写,不是interable)。系统自带的Python标准库不会出现这种低级错误,问题出在某个自定义或第三方的Python脚本(大概率是系统启动时加载的脚本)。
解决步骤:
进入可操作的命令行环境
启动系统时按Shift(UEFI系统按ESC)进入GRUB菜单,选择「Advanced options for Ubuntu」,再选「recovery mode」,最后选择「root drop to root shell prompt」。进入后先挂载系统分区为可写:mount -o remount,rw /定位错误的Python文件
使用grep搜索包含错误拼写的脚本:# 搜索拼写错误的模块名 grep -r "colections" /etc /usr/local /home --include="*.py" # 搜索拼写错误的对象名 grep -r "interable" /etc /usr/local /home --include="*.py"这会列出所有包含错误拼写的Python文件路径。
修正拼写错误
用文本编辑器(比如nano)打开找到的文件,将:colections改为collectionsinterable改为Iterable(注意首字母大写)
验证修复并重启
修正后执行exit退出root shell,选择「resume normal boot」重启系统,问题应该就能解决。
如果找不到错误脚本,可尝试重新安装系统自带的Python 3.10:
apt update && apt reinstall python3.10
内容的提问来源于stack exchange,提问作者ramin
相关产品推荐
相关产品推荐

