caffe libcudnn.so.6: cannot open shared object file: No such file or directo

时间:2021-06-29 08:45:19

更新cudnn版本至cuDNN v6 ImportError: libcudart.so.6.0: cannot open shared object file: No such file or directory

参考:http://blog.csdn.net/qq_17135515/article/details/78397002

tensorflow1.3和1.4版本都要求cuDNN v6版本详见tensorflow官网 当你更新tensorflow版本以获取更多支持时,再次运行tensorflow时会报如下错误:

caffe也会报这个错误:

[xx_xx@xxxx ~]$ python multiply.py
Traceback (most recent call last): File "multiply.py", line 2, in <module> import tensorflow as tf File "/home/luohao/.usr/bin/python2.7.10/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module> from tensorflow.python import * File "/home/luohao/.usr/bin/python2.7.10/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 22, in <module> from tensorflow.python.client.client_lib import * File "/home/luohao/.usr/bin/python2.7.10/lib/python2.7/site-packages/tensorflow/python/client/client_lib.py", line 35, in <module> from tensorflow.python.client.session import InteractiveSession File "/home/luohao/.usr/bin/python2.7.10/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 11, in <module> from tensorflow.python import pywrap_tensorflow as tf_session File "/home/luohao/.usr/bin/python2.7.10/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module> _pywrap_tensorflow = swig_import_helper() File "/home/luohao/.usr/bin/python2.7.10/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description) **ImportError: libcudart.so.6.0: cannot open shared object file: No such file or directory**


可以从ImportError: libcudart.so.6.0: cannot open shared object file: No such file or directory 看出是因为没有libcudart.so.6.0文件,所以要升级cudnn到cuDNN v6。

问题描述

tensorflow官网提供的Ubuntu的安装页面,GPU的二进制版本要求cuDNN v6。 但是,现有cuDNN版本为5.1。

系统信息

  • Linux Ubuntu 16.04
  • GPU版本tensorflow1.3 或者 tensorflow1.4

1.下载cuDNN v6 cudnn-8.0-linux-x64-v6.0.tgz

方法一:通过nvidia官网,注册账号,验证邮箱,填写问卷后 通过右上角搜索cuDNN Archive | NVIDIA Developer 进入到页面选择相应版本的cudnn下载。(注:官网页面可能会出错而找不到对应版本,那就用方法二喽~)
方法二:baidu or google 搜索相应cudnn版本下载

2.将下载好的cudnn拷贝到CUDA-8.0的目录下并解压:

sudo tar -zxvf cudnn-8.0-linux-x64-v6.0.tgz
2

解压后会在当前目录下生成一个cuda文件夹,里面包含了include以及lib64两个子目录:

cuda/include/cudnn.h
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.6
cuda/lib64/libcudnn.so.6.0.21
cuda/lib64/libcudnn_static.a

3.将解压得的两个子目录中的文件复制到cuda-8.0对应的安装目录。这里以cuda的安装目录为/usr/local/cuda-8.0/为例,这个目录下也包含include/以及lib64/这两个子文件夹,将生成的include以及lib64两个子目录中的内容复制过来即可。*

sudo cp ./cuda/include/cudnn.h /usr/local/cuda-8.0/include
sudo cp ./cuda/lib64/* /usr/local/cuda-8.0/lib64/

4在/usr/local/cuda-8.0/lib64/目录下进行执行以下命令手动生成符号链接。

sudo rm -rf libcudnn.so libcudnn.so.6 #删除原有的两个符号链接
sudo ln -s libcudnn.so.6.0.21 libcudnn.so.6 #生成新的符号链接
sudo ln -s libcudnn.so.6 libcudnn.so #生成新的符号链接#后面是软链接,前面是实体文件

然后进行操作:
sudo cp /usr/local/cuda-8.0/lib64/libcudnn.so /usr/local/lib/libcudnn.so && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcudnn.so.6 /usr/local/lib/libcudnn.so.6 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcusolver.so.8.0 /usr/local/lib/libcusolver.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcufft.so.8.0 /usr/local/lib/libcufft.so.8.0 && sudo ldconfig

现在cudnn版本已经更新完毕,会支持高版本的tensorflow

还有一种情况,libcudnn安装对了,但是pycahrm没有这个目录:

命令行:export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64

这个也ok:

pycharm中,还有可能对cuda路径操作不对:

在菜单Edit->Run configurations 中,手动设置Environment variables,添加LD_LIBRARY_PATH的内容,即可解决问题。

caffe libcudnn.so.6: cannot open shared object file: No such file or directo

caffe libcudnn.so.6: cannot open shared object file: No such file or directo