深度学习|ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

一、问题描述 import tensorflow 时遇到错误,报错如下:

Traceback (most recent call last): File "", line 1, in File "/home/thz/anaconda3/envs/python2/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in from tensorflow.python import * File "/home/thz/anaconda3/envs/python2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in from tensorflow.python import pywrap_tensorflow File "/home/thz/anaconda3/envs/python2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "/home/thz/anaconda3/envs/python2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "/home/thz/anaconda3/envs/python2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "/home/thz/anaconda3/envs/python2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directoryFailed to load the native TensorFlow runtime.See https://www.tensorflow.org/install/install_sources#common_installation_problemsfor some common reasons and solutions.Include the entire stack trace above this error message when asking for help. >>>

主要报错是:
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

二、问题解决 【深度学习|ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory】方法一:
tensorflow 与 CUDA 有版本对应关系:
表格来源:https://www.tensorflow.org/install/source#common_installation_problems
tensorflow 版本 Python 版本 编译器 构建工具 cuDNN CUDA
tensorflow-2.1.0 2.7、3.5-3.7 GCC 7.3.1 Bazel 0.27.1 7.6 10.1
tensorflow-2.0.0 2.7、3.3-3.7 GCC 7.3.1 Bazel 0.26.1 7.4 10.0
tensorflow_gpu-1.14.0 2.7、3.3-3.7 GCC 4.8 Bazel 0.24.1 7.4 10.0
tensorflow_gpu-1.13.1 2.7、3.3-3.7 GCC 4.8 Bazel 0.19.2 7.4 10.0
tensorflow_gpu-1.12.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.11.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.10.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.9.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.11.0 7 9
tensorflow_gpu-1.8.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.10.0 7 9
tensorflow_gpu-1.7.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.9.0 7 9
tensorflow_gpu-1.6.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.9.0 7 9
tensorflow_gpu-1.5.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.8.0 7 9
tensorflow_gpu-1.4.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.5.4 6 8
tensorflow_gpu-1.3.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.5 6 8
tensorflow_gpu-1.2.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.5 5.1 8
tensorflow_gpu-1.1.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.2 5.1 8
tensorflow_gpu-1.0.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.2 5.1 8
按照这个对应关系安装就可以了,但不是严格一一对应的,只要版本不相差太远就好,比如我开始的对应是:
CUDA-10.2、tensorflow_gpu-1.4.0
表中的 tensorflow-2.1.0 才支持到 CUDA-10.1,我将 tensorflow_gpu-1.4.0 换成了 tensorflow_gpu-1.14.0,问题解决。
方法二:
比较简单,重装 cudatoolkit,如果是使用 conda 虚拟环境,执行下面的命令:
conda install cudatoolkit=9.0

其中 cudatoolkit 版本号是你的报错中 libcublas.so.9.0 中的版本号。

    推荐阅读