“Could not load dynamic library ‘libcudnn.so.8′” when running tensorflow on ubuntu 20.04

We Are Going To Discuss About “Could not load dynamic library ‘libcudnn.so.8′” when running tensorflow on ubuntu 20.04. So lets Start this Python Article.

“Could not load dynamic library ‘libcudnn.so.8′” when running tensorflow on ubuntu 20.04

  1. How to solve “Could not load dynamic library 'libcudnn.so.8'” when running tensorflow on ubuntu 20.04

    So I had the same issue. As the comments say, it's because you need to install CUDNN. For that, there is a guide here.
    But as I know already your distro (Ubuntu 20.04) I can give you the command lines already:
    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/${last_public_key}.pub sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" sudo apt-get update sudo apt-get install libcudnn8 sudo apt-get install libcudnn8-dev
    where ${last_public_key} is the last public key (file with .pub extension) published on https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/. (At May 9th 2022 when this post was edit, it was 3bf863cc.pub).
    And if you want to install a specific version, the last 2 commands would be replaced with
    sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version} sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}
    where
    ${cudnn_version} is for example 8.2.4.* and ${cuda_version} is for example cuda11.0 (as I see you have 11.0 on the command nvidia-smi, although I have not tested it as mine was 11.4 but I guess it should work Ok)

  2. “Could not load dynamic library 'libcudnn.so.8'” when running tensorflow on ubuntu 20.04

    So I had the same issue. As the comments say, it's because you need to install CUDNN. For that, there is a guide here.
    But as I know already your distro (Ubuntu 20.04) I can give you the command lines already:
    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/${last_public_key}.pub sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" sudo apt-get update sudo apt-get install libcudnn8 sudo apt-get install libcudnn8-dev
    where ${last_public_key} is the last public key (file with .pub extension) published on https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/. (At May 9th 2022 when this post was edit, it was 3bf863cc.pub).
    And if you want to install a specific version, the last 2 commands would be replaced with
    sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version} sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}
    where
    ${cudnn_version} is for example 8.2.4.* and ${cuda_version} is for example cuda11.0 (as I see you have 11.0 on the command nvidia-smi, although I have not tested it as mine was 11.4 but I guess it should work Ok)

Solution 1

So I had the same issue. As the comments say, it’s because you need to install CUDNN. For that, there is a guide here.

But as I know already your distro (Ubuntu 20.04) I can give you the command lines already:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/${last_public_key}.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
sudo apt-get install libcudnn8
sudo apt-get install libcudnn8-dev

where ${last_public_key} is the last public key (file with .pub extension) published on https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/. (At May 9th 2022 when this post was edit, it was 3bf863cc.pub).

And if you want to install a specific version, the last 2 commands would be replaced with

sudo apt-get install libcudnn8=${cudnn_version}-1+${cuda_version}
sudo apt-get install libcudnn8-dev=${cudnn_version}-1+${cuda_version}

where
${cudnn_version} is for example 8.2.4.* and ${cuda_version} is for example cuda11.0 (as I see you have 11.0 on the command nvidia-smi, although I have not tested it as mine was 11.4 but I guess it should work Ok)

Original Author Agustin Barrachina Of This Content

Solution 2

I had the same issue and linux OS is Centos7-6 for me. Since I don’t have sudo access on this machine, I solved the issue by installing cudnn from the anaconda website

In the environment where the latest tensorflow flow is installed :

conda install -c anaconda cudnn

You can check the package install using conda list : ( I had previously installed the cudatoolkit from anaconda )

Name                      Version              Build  Channel
cudatoolkit               11.3.1               h2bc3f7f_2
cudnn                     8.2.1                cuda11.3_0

You can check if tensorflow and the gpus are talking to each other :

(tf2_6) [[email protected] envs]$ python
Python 3.8.12 (default, Oct 12 2021, 13:49:34)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> gpus = tf.config.experimental.list_physical_devices('GPU')
>>> for gpu in gpus:
...     print("Name:", gpu.name, "  Type:", gpu.device_type)
...
Name: /physical_device:GPU:0   Type: GPU
Name: /physical_device:GPU:1   Type: GPU

Original Author ML_Passion Of This Content

Solution 3

I used in Ubuntu 22.04

sudo apt install nvidia-cudnn

Original Author André Berenguel Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment