ubuntu16.04上的Tensorflow-gpu安装问题

时间:2018-04-10 15:05:08

标签: python python-3.x tensorflow

我有一台运行Ubuntu16.04的linux机器,NVIDIA GEFORCE1060。我正在运行python3.6(使用anaconda安装)和CUDA9.1

我很乐意用CPU编写tensorlow编码,没有任何问题。然后我想安装tensorflow-gpu以及我遇到问题的地方。

首次成功安装cudnn7.1.2(make并成功运行mnist-cudnn

pip3 install tensorflow_gpu-1.7.0-cp36-cp36m-manylinux1_x86_64.whl

import tensorflow as tf

我收到以下错误

Traceback (most recent call last):
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/bony/anaconda3/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/home/bony/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *  # pylint: disable=redefined-builtin
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/bony/anaconda3/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/home/bony/anaconda3/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/home/bony/anaconda3/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
Failed to load the native TensorFlow runtime.

任何帮助解决这个问题并让我继续tensorflow-gpu将不胜感激

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

  • 我在Ubuntu 16.04上遇到了同样的问题
  • 这是我的解决方案
  • 首先,在NVIDIA requirements to run TensorFlow with GPU support的官方网页上,我们可以知道:

    • CUDA®Toolkit9.0。
    • cuDNN v7.0。
    • 具有CUDA Compute Capability 3.0或更高版本的GPU卡,用于从源代码构建,3.5或更高版本用于我们的二进制文件
  • 所以卸载Cuda9.1。

    • 如果您不知道如何卸载,可以在Ubuntu软件中安装Synaptic Package Manager,然后在搜索cuda中选择Mark for complete removal
    • 应用
    • 重新加载Synaptic Package Manager
    • 选择Cuda-9.0 Mark for install
    • 应用
  • 安装cnDNN v7.0

    • 我下载了cuDNN v7.0.5 Developer Library for Ubuntu16.04 (Deb),因为它是Cuda-9.0的最新版本cuDNN v7.0
  • 安装cuda-command-line-tools

    sudo apt-get install cuda-command-line-tools

    • 如果找不到cuda-command-line-tools

      sudo apt-cache search cuda-command-line-tool

      然后选择安装cuda-command-line-tool-9.0

  • 按照官方文档,将其路径添加到LD_LIBRARY_PATH环境变量

    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}/usr/local/cuda/extras/CUPTI/lib64

  • 我正在使用Anaconda3,我使用conda命令创建环境包含py3.5名称py35。

  • 因此,我使用source activate py35并使用pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.7.0-cp35-cp35m-linux_x86_64.whl
  • 您可以选择tensorflow-gpu哪一个支持您的python版本。

  • Validate your installation

    • 运行一个简短的TensorFlow程序 import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello))
    • 如果系统输出Hello, TensorFlow!,那么您就可以开始编写TensorFlow程序。

enter image description here 祝你好运。