27

I encountered the following error when trying to run a TensorFlow program:

ImportError: libcudnn.Version: cannot open shared object file: No such file or director
Barry Rosenberg
  • 2,117
  • 4
  • 15
  • 18
  • if this is still an issue - recommend checking my answer at https://stackoverflow.com/a/61563579/1215913 – Alex May 02 '20 at 17:47

8 Answers8

39

Just download cuDNN 5.1 and follow the steps (Tested on Ubuntu 16.04, CUDA toolkit 8.0 )

$ tar xvzf cudnn-8.0-linux-x64-v5.1-ga.tgz
$ sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

Now set Path variables

$ vim ~/.bashrc

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda

and done

For more details, you can check this site

thesecretmaster
  • 1,950
  • 1
  • 27
  • 39
Ankit Kumar
  • 1,680
  • 1
  • 22
  • 35
  • Although the TensorFlow instructions explicitly state "Ensure that you create the CUDA_HOME environment variable as described in the NVIDIA documentation." this step is somewhat easy to fail at. Execute as stated above by @ankit and all will be swell. Don't forget to reload your newly added env vars by `source ~/.bashrc` before moving on. – Sietse̩̯ van der Meer Jun 14 '17 at 03:51
  • @empty download from [here](https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod_20161129/8.0/cudnn-8.0-linux-x64-v5.1-tgz) – Ankit Kumar Aug 09 '17 at 06:16
  • 6
    The solution needs to adapt to the version of cuDNN that the current TensorFlow expects. As of Nov. 31, 2017, it requires cuDNN 6. The error message with 'import tensorflow' would indicate the version required. For example, "ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory" indicates that it expects libcudnn.so.6 – Yu Shen Oct 31 '17 at 19:42
  • From the link in this answer: Now you need to update your bash file... $ gedit ~/.bashrc With the text editor open, scroll to the bottom and put in these lines: export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64" export CUDA_HOME=/usr/local/cuda Save and close it. Then reload as Stacky mentions with source ~/.bashr – user3496060 Mar 20 '18 at 04:43
10

It appears TensorFlow now supports cudNN 6.0. I was getting errors with cudNN 5.1.

Using TensorFlow version 1.3.0.

If you're getting

ImportError: libcudnn.so.6: cannot open shared object file: No such file or directory

Try using 6.0

Kevin Dewalt
  • 757
  • 9
  • 24
  • Exactly! This is a bug in tensorflow installation guide (they should update the recommended cudnn to 6, since it doesn't work with 5.1). I wasted a few good hours on this. – ezfn Aug 18 '17 at 11:01
6

At this time Tensorflow does not support cuDNN 6. If your error is that it cannot find libcudnn.so.5 and you have only installed cuDNN 6 which provides libcudnn.so.6, you'll have to install cuDNN 5 until cuDNN 6 support is introduced. There's an open bug report that you can follow on the Tensorflow Github page to find out when they start supporting cuDNN 6.

mmdanziger
  • 4,466
  • 2
  • 31
  • 47
  • I wan't sure which one to install, so I just went with 5.1 because that's what the docs said. Buuut the docs also said to use cuda 7.x. It's hard to set up these environments when there are so many versions of things and the docs are slighttly wrong! http://developer2.download.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod/doc/cudnn_install.txt?F3FJdd7MWqtI7nGkyMVGrQTBf7x4TpOQKPwjNxyLlD5Jm6wFHZvYyj6XLd47Vy0yxeGMLfH4CiaIPyQQk-FiC2gIB3y16u4Lc-4Vlh1CHgkCseXk76Z9AdsxYDiRmSlrrlbAgmx8lw6yy8hFhkSOmNd0U5zMiZ8HDZH_x7F34QLM2lWE. –  May 14 '17 at 04:51
  • I simply added the needed version files to the installation path and it works. Untill they support cudnn 6 this is the best approach I've found – Jorge Lima Jun 03 '17 at 18:04
  • @user2918461 your link is dead :/ – Joran Dox Jan 02 '18 at 08:16
4

I faced this issue. In my case my eclipse gave this error but tensorflow was running smoothly in terminal. So after cuDNN installation or pasting the files related to cudNN in /usr/local/cuda/lib64 and /usr/local/cuda/include, I figured that the command sudo ldconfig -v also has to be executed in the terminal.

After that it should work.

This is assuming that one has already set the following environment variables as per the specifications in CUDA installation procedure by NVIDIA: LD_LIBRARY_PATH, PATH, CUDA_HOME

Aditya
  • 533
  • 3
  • 11
2

You may not have installed the correct version of cuDNN.

To determine the correct version of cuDNN, see the NVIDIA requirements to run TensorFlow with GPU support.

Barry Rosenberg
  • 2,117
  • 4
  • 15
  • 18
  • 1
    Even with the right version of cuda (8.0) and cudnn (5.1), this error still happens when using the pip install method from https://www.tensorflow.org/install/install_linux#installing_with_native_pip – mstreffo Apr 29 '17 at 12:18
2

Make sure the $LD_LIBRARY_PATH environment variable is set to the correct path.

From the cuDNN Install Guide:

ALL PLATFORMS

Extract the cuDNN archive to a directory of your choice, referred to below as <installpath>.
Then follow the platform-specific instructions as follows.

LINUX

cd <installpath>
export LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH

Add <installpath> to your build and link process by adding -I<installpath> to your compile
line and -L<installpath> -lcudnn to your link line.

OS X

cd <installpath>
export DYLD_LIBRARY_PATH=`pwd`:$DYLD_LIBRARY_PATH

Add <installpath> to your build and link process by adding -I<installpath> to your compile
line and -L<installpath> -lcudnn to your link line.

WINDOWS

Add <installpath> to the PATH environment variable.

In your Visual Studio project properties, add <installpath> to the Include Directories 
and Library Directories lists and add cudnn.lib to Linker->Input->Additional Dependencies.
  • 1
    I had to set the LD_LIBRARY_PATH to /lib64. I installed cudnn to /opt/cuda. In this directory there were two folders, include and lib64. If I set LD_LIBRARY_PATH="/opt/cuda":$LD_LIBRARY_PATH I got the error indicated in this question. –  May 14 '17 at 04:53
1

I was able to solve problem by changing my cudNN installation from cudNN 6.0 to cudNN 5.1. cudNN 6.0 has the file libcudnn.so.6 while cudNN 5.1 has the file libcudnn.so.5.

1

Download and install cuDNN from https://developer.nvidia.com/rdp/cudnn-download

for ubuntu 18.04 and cuda 10.1:

sudo dpkg -i libcudnn7_7.5.0.56-1+cuda10.1_amd64.deb