Could not load dynamic library 'libnvinfer.so.6'

Question:

I am trying to normally import the TensorFlow python package, but I get the following error:

enter image description here

Here is the text from the above terminal image:

2020-02-23 19:01:06.163940: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
2020-02-23 19:01:06.164019: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
2020-02-23 19:01:06.164030: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
<module 'tensorflow_core._api.v2.version' from '/home/saman/miniconda3/envs/testconda/lib/python3.7/site-packages/tensorflow_core/_api/v2/version/__init__.py'
Asked By: saman jahangiri

||

Answers:

This is a warning, not an error. You can still use TensorFlow. The shared libraries libnvinfer and libnvinfer_plugin are optional and required only if you are using nvidia’s TensorRT capabilities.

To suppress this and all other warnings, set the environment variable TF_CPP_MIN_LOG_LEVEL="2".

TensorFlow’s installation instructions list the GPU dependencies (current as of December 13 2022):

The following NVIDIA® software are only required for GPU support.

  • NVIDIA® GPU drivers version 450.80.02 or higher.
  • CUDA® Toolkit 11.2.
  • cuDNN SDK 8.1.0.
  • (Optional) TensorRT to improve latency and throughput for inference.
Answered By: jkr

Most of these messages are warnings, not errors. They just mean that libraries to use an Nvidia GPU are not installed, but you don’t have to have any Nvidia GPU to use Tensorflow so you don’t need these libraries. The comment by jakub tells how to turn off the warnings:

export TF_CPP_MIN_LOG_LEVEL="2"

However, I too run Tensorflow without Nvidia stuff and there is one more message that is an error, not a warning:

2020-04-10 10:04:13.365696: E tensorflow/stream_executor/cuda/cuda_driver.cc:351] failed call to cuInit: UNKNOWN ERROR (303)

It should be irrelevant because it too refers to cuda, which is for Nvidia. It doesn’t seems to be a fatal error though.

Answered By: zizzler

I got this warning as a result of (accidental) update of libvnifer6 package. It got updated to 6.0.1-1+cuda10.2 while original installation used 6.0.1-1+cuda10.1.

After I uninstalled packages referencing cuda10.2 and re-ran

sudo apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 
    libnvinfer-dev=6.0.1-1+cuda10.1 
    libnvinfer-plugin6=6.0.1-1+cuda10.1

this warning went away.

Answered By: Yevgen Yampolskiy

You can download the zip file of tensorRT 6 and then should paste the x86 linux folder file to /usr/lib/cuda make sure that the lib folder in the x86_linux folder that you have downloaded should be renamed to lib64 . After pasteing all the files in the cuda directory reboot the system . Now Cuda and TensorRT engine will run smoothly in your system.

Answered By: Shekhar Maheswari

I spent like 5 hrs solving this issue. For my case, I believe it means that you have the wrong version of library. libnvinfer.so.6 is located at ‘TensorRT-*/lib’ and the number 6 means tensorFlow is looking for the libvinfer of TensorRT6. So if it’s "could not load dynamic library libnvinfer.so.5", it means that you need TensorRT 5 to run the code.

Same as above, if it is showing Could not load dynamic library ‘libcudart.so.10.0’, you need the library in cuda 10.0 to run the code.

So updating your tensorrt/Cuda/Cudnn to match your tensorflow version would help. Note that your tensorrt/cuda/cudnn version should also match each other.

Answered By: Tony Jiang
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb

sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt-get update

Little bit of an info from jakub’s answer. This could occur if you don’t install the ‘machine-learning’ repo. Try this if you already install CUDA successfully but still geting the error.

Then Install TensorRT. Requires that libcudnn7 is installed above.

sudo apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 
    libnvinfer-dev=6.0.1-1+cuda10.1 
    libnvinfer-plugin6=6.0.1-1+cuda10.1
Answered By: Nirmal Hasantha