yolov5 MMCV依赖库 报错(2个错误)

发布于:2024-04-18 ⋅ 阅读:(35) ⋅ 点赞:(0)

1.报错内容

错误1: ImportError: libtorch_cuda_cu.so: cannot open shared object file: No such file or directory
错误2:ModuleNotFoundError: No module named ‘mmcv._ext’

2. 原因分析

python 、torch、mmcv版本兼容问题

3.解决方法

首先运行代码,查看torch版本

import torch
print(torch.__version__)

在这里插入图片描述

2.2.2+cu121" 表示 PyTorch 的版本号为 2.2.2,cuda为12.1

参考下面MMCV文档
MMdetection的环境相关,MMCV和PyTorch、CUDA版本对应
MMCV介绍
MMCV安装

在这里插入图片描述
在这里插入图片描述
如果上述都没有找到合适版本,则需要torch和cuda版本切换

这里我选用cuda11.3和torch1.11.0

在这里插入图片描述
torch和cuda安装命令(选中一种即可)

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113

对应版本mmcv安装命令如下:

pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11/index.html

在这里插入图片描述

3. 总结

(总结部分只适用于我自己的环境,上面是通用步骤)

环境:RTX4090、python3.8.x、pytorch1.11.0、cuda11.3、ubuntu20.04

torch和cuda安装命令

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 torchaudio==0.11.0 --extra-index-url https://download.pytorch.org/whl/cu113

对应版本mmcv安装命令

pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11/index.html

完美解决截图:
在这里插入图片描述