You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

导入torchvision报错:AttributeError: module 'torch.jit' has no attribute 'unused'

解决PyTorch与TorchVision版本不兼容导致的AttributeError: module 'torch.jit' has no attribute 'unused'问题

你这明显是踩了PyTorch版本匹配的坑!咱们先把问题根源说清楚:

你安装的torchvision==0.5.0里用到了torch.jit.unused这个装饰器,但这个属性是PyTorch 1.5.0及以上版本才新增的,而你装的是torch==1.4.0,老版本里根本没有这个东西,自然就报找不到属性的错了——核心就是版本不兼容!

解决方案:安装严格匹配的PyTorch与TorchVision版本组合

给你两个可选方向,根据自己的需求选:

方向1:升级PyTorch适配TorchVision 0.5.0

先卸载现有版本:

pip uninstall -y torch torchvision

然后安装刚好适配torchvision==0.5.0的torch==1.5.0:

pip install torch==1.5.0 torchvision==0.5.0 -f https://download.pytorch.org/whl/torch_stable.html

方向2:降级TorchVision适配PyTorch 1.4.0

如果你不想升级PyTorch,那就把TorchVision降到和1.4.0严格匹配的0.4.2版本:

pip uninstall -y torch torchvision
pip install torch==1.4.0 torchvision==0.4.2 -f https://download.pytorch.org/whl/torch_stable.html

验证安装是否成功

打开Python交互环境,输入以下命令:

import torch
import torchvision
print(f"PyTorch版本: {torch.__version__}")
print(f"TorchVision版本: {torchvision.__version__}")

如果没有报错,且版本对应上了,就说明问题解决了。

另外提醒下:PyTorch和TorchVision的版本对应关系是官方严格规定的,以后安装的时候一定要注意匹配,避免这类低级但头疼的版本问题~

内容的提问来源于stack exchange,提问作者user8270077

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 21:32:31