出现Error: libxxxxxxx: cannot open shared object file: No such file or directory 的可能有效解决方法如下:
注:前提是本地能够找到libxxxxxxx,但一直提示:
Could not load library libxxxxxxx. Error: libxxxxxxx: cannot open shared object file: No such file or directory
Please make sure libxxxxxxx is in your library path!
这里以libcudnn_cnn_infer.so.8为例。
先运行:
ldconfig -p | grep cuda
得到输出:
libcudart.so.11.0 (libc6,x86-64) => /usr/local/cuda-11.3/targets/x86_64-linux/lib/libcudart.so.11.0
libcudart.so.10.2 (libc6,x86-64) => /lib/libcudart.so.10.2
libcudart.so (libc6,x86-64) => /usr/local/cuda-11.3/targets/x86_64-linux/lib/libcudart.so
libcudadebugger.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libcudadebugger.so.1
libcuda.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libcuda.so.1
libcuda.so.1 (libc6) => /lib/i386-linux-gnu/libcuda.so.1
打比方说,libcudart.so.11.0,是放到/usr/local/cuda-11.3/targets/x86_64-linux/lib/目录下面的。
然后找到本地的libcudnn_cnn_infer.so.8:
sudo find / -name "libcudnn_cnn_infer.so.8"
得到结果:
/home/ai/miniconda3/lib/python3.7/site-packages/nvidia/cudnn/lib/libcudnn_cnn_infer.so.8
/home/ai/miniconda3/pkgs/pytorch-2.0.1-py3.10_cuda11.7_cudnn8.5.0_0/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_infer.so.8
/home/ai/miniconda3/pkgs/pytorch-1.12.1-py3.7_cuda11.3_cudnn8.3.2_0/lib/python3.7/site-packages/torch/lib/libcudnn_cnn_infer.so.8
/home/ai/miniconda3/pkgs/pytorch-2.0.0-py3.10_cuda11.8_cudnn8.7.0_0/lib/python3.10/site-packages/torch/lib/libcudnn_cnn_infer.so.8
然后将找到的libcudnn_cnn_infer.so.8复制到上面通过ldconfig得到的路径:
sudo cp -rf /home/ai/miniconda3/lib/python3.7/site-packages/nvidia/cudnn/lib/libcudnn_cnn_infer.so.8 /usr/local/cuda-11.3/targets/x86_64-linux/lib/
然后:
sudo ldconfig
再通过ldconfig -p | grep cuda查看最新的输出:
libcudnn_cnn_infer.so.8 (libc6,x86-64) => /usr/local/cuda-11.3/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
libcudart.so.11.0 (libc6,x86-64) => /usr/local/cuda-11.3/targets/x86_64-linux/lib/libcudart.so.11.0
libcudart.so.10.2 (libc6,x86-64) => /lib/libcudart.so.10.2
libcudart.so (libc6,x86-64) => /usr/local/cuda-11.3/targets/x86_64-linux/lib/libcudart.so
libcudadebugger.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libcudadebugger.so.1
libcuda.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libcuda.so.1
libcuda.so.1 (libc6) => /lib/i386-linux-gnu/libcuda.so.1
就能看到 libcudnn_cnn_infer.so.8了。