Could not load dynamic library ‘libnvinfer.so.6’; dlerror:
libnvinfer.so.6: cannot open shared object file: No such file or
directory; LD_LIBRARY_PATH: :/usr/local/cuda-10.1/lib64
报错后仍可以正常运行,但是发现GPU并未调用,只跑在CPU上。在尝试多次重装CUDA10.1、CUDA ToolKit等后,均无效。
CUDA的Python相关库cudnn、cudatoolkit等没有安装全,并不是CUDA10.1等的锅(当然如果CUDA10.1等没有装也会有其他报错,而不是缺失库)
Ubuntu+Python3.6+TensorFlow2.1.0
不管什么环境,出现此类报错解决的思路都类似。
1.pip或者conda卸载掉所有的tensorflow包
2.如果没有安装CUDA等,先安装它们
3.用conda安装包
以上安装方法可以参考我的博客,进入进行搜索关键词即可:
https://blog.csdn.net/weixin_41194129?spm=1001.2101.3001.5343
不要用pip安装TensorFlow包,要用conda来安装包(前提是要有Anaconda或miniconda3),输入conda指令:
conda install tensorflow-gpu==2.1.0
conda会自动将TensorFlow相关的库给安装齐全,如cudnn、cudatoolkit、tensorflow-base等。截图如下:
参考我的博客测试代码:https://blog.csdn.net/weixin_41194129/article/details/114238772
GPU显示测试成功:
其他问题1:
Could not load dynamic library ‘libcudart.so.11.0‘; dlerror: libcudart.so.11.0: cannot open shared o
解决方法同上,只需输入以下指令即可:
conda install cudatoolkit=11.0
解决方法:
如果还是无法解决,就在本机搜索sudo find / -name libnvinfer.so.6
sudo find / -name libnvinfer.so.6
[sudo] password for :
Sorry, try again.
[sudo] password for :
find: ‘/run/user/1000/gvfs’: Permission denied
/var/lib/docker/overlay2/7acded02178b710e777fa27574bb3ea89420c0464927b53144f8c4ea102e690d/diff/usr/lib/x86_64-linux-gnu/libnvinfer.so.6
/var/lib/docker/overlay2/7acded02178b710e777fa27574bb3ea89420c0464927b53144f8c4ea102e690d/merged/usr/lib/x86_64-linux-gnu/libnvinfer.so.6
然后根据搜索结果路径将.so拷贝到你对应的python环境的lib目录下:我的是miniconda虚拟环境下:envs/py36/lib
/envs/py36/lib$ sudo scp /var/lib/docker/overlay2/7acded02178b710e777fa27574bb3ea89420c0464927b53144f8c4ea102e690d/diff/usr/lib/x86_64-linux-gnu/libnvinfer.so.6 .
重新进入python环境,再次进行测试:
python
Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 21:15:04)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2021-09-10 13:23:31.503203: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer.so.6
2021-09-10 13:23:31.503462: 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; LD_LIBRARY_PATH: /usr/lcoal/cuda-10.0/lib64:
2021-09-10 13:23:31.503484: 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.
发现缺少Could not load dynamic library ‘libnvinfer_plugin.so.6’,采用上述同样的方法即可解决:
python
Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 21:15:04)
[GCC 7.3.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.import tensorflow as tf
2021-09-10 13:26:45.800104: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer.so.6
2021-09-10 13:26:46.144635: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer_plugin.so.6
GPU测试结果:可用
>>> print(tf.__version__,tf.test.is_gpu_available())
WARNING:tensorflow:From :1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2021-09-10 13:27:30.476868: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-09-10 13:27:30.509315: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1999965000 Hz
2021-09-10 13:27:30.510074: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5591ee038fd0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-09-10 13:27:30.510126: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2021-09-10 13:27:30.514879: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2021-09-10 13:27:30.594270: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 13:27:30.594614: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5591ee115000 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-09-10 13:27:30.594634: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce MX130, Compute Capability 5.0
2021-09-10 13:27:30.594768: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 13:27:30.595035: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:02:00.0 name: GeForce MX130 computeCapability: 5.0
coreClock: 1.189GHz coreCount: 3 deviceMemorySize: 1.96GiB deviceMemoryBandwidth: 37.33GiB/s
2021-09-10 13:27:30.595072: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-09-10 13:27:30.595111: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2021-09-10 13:27:30.596418: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2021-09-10 13:27:30.596665: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2021-09-10 13:27:30.598136: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2021-09-10 13:27:30.598901: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2021-09-10 13:27:30.598936: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2021-09-10 13:27:30.599009: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 13:27:30.599302: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 13:27:30.599529: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
2021-09-10 13:27:30.599554: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2021-09-10 13:27:30.858511: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1096] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-09-10 13:27:30.858543: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] 0
2021-09-10 13:27:30.858549: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] 0: N
2021-09-10 13:27:30.858712: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 13:27:30.858977: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-09-10 13:27:30.859200: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1241] Created TensorFlow device (/device:GPU:0 with 1027 MB memory) -> physical GPU (device: 0, name: GeForce MX130, pci bus id: 0000:02:00.0, compute capability: 5.0)
2.1.0 True
参考的原文链接:https://blog.csdn.net/weixin_44607626/article/details/110507123