21

I have recently installed tensorflow-gpu using pip. But when I am importing it it is giving the following error:

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

I have gone through all the answers of stackoverflow related to this issue but none of them worked for me.

libcudnn.so.7 is present in both the following directories /usr/local/cuda/lib64 and /usr/local/cuda-9.0/lib64 .

Also, I have added the following path in my .bashrc file:

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64\${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Please help me in resolving this

shivank01
  • 965
  • 3
  • 14
  • 34
  • @cdarke Yeah it is present in both /usr/local/cuda/lib64 and /usr/local/cuda-9.0/lib64 – shivank01 Jun 25 '18 at 08:56
  • 1
    What are the actual values of PATH and LD_LIBRARY_PATH in your environment? – Dr. Snoopy Jun 25 '18 at 11:51
  • @MatiasValdenegro I have mentioned the values of PATH and LD_LIBRARY_PATH in the question. – shivank01 Jun 25 '18 at 11:54
  • 1
    Those are not the values, its how you are setting them, we need the actual values that are set in your environment, just do echo $PATH and echo $LD_LIBRARY_PATH in a terminal. – Dr. Snoopy Jun 25 '18 at 11:56
  • @MatiasValdenegro The value of PATH is "-bash: /usr/local/cuda-9.0/bin:/home/tpradhan/anaconda3/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/pycharmCE2017/bin:/usr/java/latest/bin:/opt/eclipse:/opt/ideaCE/bin:/opt/libreofice6.0/:/opt/ubin:/opt/ulibs/Qt5.6.2:/opt/pycharmCE2017/bin: No such file or directory" and the value of LD_LIBRARY_PATH is "/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:}" – shivank01 Jun 25 '18 at 12:00
  • 1
    I think you can see how that the LD_LIBRARY_PATH is wrong. – Dr. Snoopy Jun 25 '18 at 12:01
  • @MatiasValdenegro Can you please elaborate? – shivank01 Jun 25 '18 at 12:02
  • Cuda and Cudnn installation are TWO different thing, and your question has been discussed at length here before: https://askubuntu.com/questions/767269/how-can-i-install-cudnn-on-ubuntu-16-04 – Peter Teoh Apr 02 '19 at 01:09

6 Answers6

14

You are setting LD_LIBRARY_PATH in the wrong way, I would recommend to do it this way (which is kind of the standard):

export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Dr. Snoopy
  • 52,950
  • 7
  • 111
  • 130
  • It is still showing the same error. Now my LD_LIBRARY_PATH is "/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:}" and path is "/home/tpradhan/venvs/tensorflow/bin:/usr/local/cuda-9.0/bin:/home/tpradhan/anaconda3/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/pycharmCE2017/bin:/usr/java/latest/bin:/opt/eclipse:/opt/ideaCE/bin:/opt/libreofice6.0/:/opt/ubin:/opt/ulibs/Qt5.6.2:/opt/pycharmCE2017/bin export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+::/home/tpradhan/.local/bin:/home/tpradhan/bin" . – shivank01 Jun 25 '18 at 12:09
  • 1
    @shivank01 Your LD_LIBRARY_PATH is still wrong, seems you have't changed anything given the output. – Dr. Snoopy Jun 25 '18 at 12:11
  • 1
    I have changed according to your answer. – shivank01 Jun 25 '18 at 12:14
  • @shivank01 On which file exactly? And did you restart the terminal after making changes? – Dr. Snoopy Jun 25 '18 at 12:16
6

You might need to download and install NVIDIA cuDNN.

Download it from https://developer.nvidia.com/rdp/cudnn-download (You have to register an account to download if you don't have). The runtime version is usually more stable than the developer version.

biendltb
  • 999
  • 11
  • 19
5

Reinstalling CudNN-7.0.5, (make sure you pick the right version from the link below) fixed this for me. You'll need to log in to your Nvidia developer account to access the link. (If you don't have an Nvidia account, creating one is straight forward);

https://developer.nvidia.com/rdp/cudnn-archive

Installation instructions for CudNN; https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

But I also encountered the following error;

Loaded runtime CuDNN library: 7.0.5 but source was compiled with: 7.4.2. CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library. If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.

Therefore, I had to once again download and install the right CuDNN version, i used the information from the above error message and installed CuDNN 7.4.2 and this fixed all the errors and everything worked fine.

Good Luck!

Sri
  • 51
  • 1
  • 3
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/24909170) – Ṃųỻịgǻňạcểơửṩ Dec 20 '19 at 15:02
  • 1
    Hi there, Thanks for the review on my answer. I have amended the answer after reviewing your comments. The above links now aren't necessarily the answer to this problem considered. But if anyone with the same issue can address the issue by following following what I have suggested, which is to re-install the right CuDNN version that contains the appropriate files and is compatible with the cuda version installed. – Sri Jan 02 '20 at 14:48
0

you add the following path in your .bashrc file:

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH


export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
0

FWIW is interested I created a shell script which installs different CUDA versions in Debian which can be easily ported to Ubuntu:

gogasca
  • 8,383
  • 5
  • 71
  • 114
-2

The reason is that some libraries are missing. Try installing

sudo apt install libcudnn7
Pipper Tetsing
  • 115
  • 1
  • 3