ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

我的问题是torch、cuda、cudnn、torchvison之间版本不匹配的问题
这篇博客给我了出路555:https://blog.csdn.net/c2250645962/article/details/105160102/
其他原因可参考解决方法 https://github.com/pytorch/pytorch/issues/10910

.创建虚拟环境

conda create -n xxx python=3.7
电脑环境是
toch1.5.0
torchvision0.3.0
cuda10.2.89
cudnn7.6.5
python3.7.11

先安装cuda10.2.89
cudnn7.6.5

在运行

import torchvision

会报错:

libcudart.so.9.0: cannot open shared object file: No such file or directory

博客推荐的是用whl更新torchvison

解决方法
本质原因:torchvision0.3支持CUDA9,不支持10,更新至torchvison0.4即可;

但是,更新torchvision到0.4会带着torch版本自动更新,
那么可以先下载torchvision0.4的安装包,

然后终端执行:

pip install torchvision-0.4.0+cu92-cp37-cp37m-manylinux1_x86_64.whl

即可。
https://download.pytorch.org/whl/torch_stable.html在这下载

torchvision-0.4.0+cu92-cp37-cp37m-manylinux1_x86_64.whl 为我下载到本地的torchvision0.4安装包

但是这样的torch被改成1.2.0的

所以参考https://yongqiang.blog.csdn.net/article/details/103385445?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

1. 放弃使用

pip install torchvision==0.3.0

2. 推荐使用 安装 torchvision 时避免更新 pytorch 到最新版本。

pip3 install --no-deps torchvision==0.4.0
pip3 install torchvision==0.4.0 --no-deps

pip install --no-deps torchvision==0.4.0
pip install torchvision==0.4.0 --no-deps
 

成功!!

安装cuda和cudnn以及之间的版本关系

分别参考https://zhuanlan.zhihu.com/p/367740437

https://blog.csdn.net/kellyroslyn/article/details/109668001

https://blog.csdn.net/weixin_42069606/article/details/105198845?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory_第1张图片
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory_第2张图片

在虚拟环境中安装cuda和cudnn

先切换到你的虚拟环境 conda activate 环境名
同时指定PyTorch和CUDAToolkit版本
如果你十分确定CUDA版本以及对应PyTorch和CUDAToolkit对应版本可运行conda install pytorch=X.X.X cudatoolkit=X.X -c pytorch

conda install pytorch=1.5.0 cudatoolkit=10.2.89 -c pytorch
conda install cudnn=7.6.5 

安装成功
验证一下版本

import torch
print(torch.__version__)
print(torch.cuda.is_available())
torch.version.cuda

ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory_第3张图片

报错解除!!!!!

你可能感兴趣的:(ML,pytorch,深度学习)