环境信息:
(1)python==3.8.20 (conda)
(2)torch==2.4.1
问题描述
笔者在更新了一次torch版本至2.4.1后,再次运行以前的代码,出现了如下报错:
ModuleNotFoundError: No module named 'torch._custom_ops'
下图用的是网上遇到了相同错误的友友给出的报错截图。
解决方案
这种问题一般是由于torch和torchvision的版本不匹配所导致的,解决方案:
(1)使用torch修复指令(使torchvision主动去匹配pytorch):
pip install torch -U
(2)重新安装torch和torchvision(可以使pytorch下降版本来匹配torchvision),像下方这样指定其中某一个包的版本,会自动匹配上合适的torchvision(笔者这里想要torch==1.11.0):
pip uninstall torch torchvision
pip install torch==1.11.0 torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple