使用Anaconda搭建TensorFlow-GPU環境

  

 

前言:python

     對於深度學習來講,各類框架torch,caffe,keras,mxnet,tensorflow,pandapanda環境要求各一,若是咱們在一臺服務器上部署了較多的這樣的框架,那麼各類莫名的衝突linux

會一直伴隨着你,吃過不少次虧以後,慢慢的接觸了Anaconda,真的是很爽的一個功能,來管理環境配置。咱們進行tensorflow安裝的時候,仍是使用Anaconda,鑑於國內牆過高git

,咱們使用了Tsinghua的鏡像文件,清華大學的Anaconda介紹地址見:https://mirror.tuna.tsinghua.edu.cn/help/anaconda/    github

這裏記錄下linux的安裝方式:ubuntu

 所使用的系統: ubuntu16.10

  安裝步驟
        1: 先登陸到這個頁面:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 
       2. 下載: wget -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda2-2.4.1-Linux-x86_64.sh
        3. 運行: bash  Anaconda2-2.i.1-Linux-x86_64.sh [中間會有幾個詢問,所有設置yes或者y]
       4. 設置鏡像倉庫:
        TUNA 還提供了 Anaconda 倉庫的鏡像,運行如下命令:        conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
          conda config --set show_channel_urls yes      便可添加 Anaconda Python 免費倉庫。      運行 conda install numpy 測試一下吧。 5. 安裝tensorflow:
        5.1 查詢conda下的tensorflow能夠利用的鏡像:
      anaconda search -t conda tensorflow

  大概會出現這些信息:api

gxjun@gxjun:~$ anaconda search -t conda tensorflow
Using Anaconda API: https://api.anaconda.org
Run 'anaconda show <USER/PACKAGE>' to get more details:
Packages:
     Name                      |  Version | Package Types   | Platforms      
     ------------------------- |   ------ | --------------- | ---------------
     HCC/tensorflow            |    1.0.0 | conda           | linux-64       
     HCC/tensorflow-cpucompat  |    1.0.0 | conda           | linux-64       
     HCC/tensorflow-fma        |    1.0.0 | conda           | linux-64       
     SentientPrime/tensorflow  |    0.6.0 | conda           | osx-64         
                                          : TensorFlow helps the tensors flow
     acellera/tensorflow-cuda  |   0.12.1 | conda           | linux-64       
     anaconda/tensorflow       |    1.1.0 | conda           | linux-ppc64le, linux-64, osx-64, win-64
     anaconda/tensorflow-gpu   |    1.1.0 | conda           | linux-ppc64le, linux-64, win-64
     conda-forge/r-tensorflow  |      0.7 | conda           | linux-64, osx-64, win-64
     conda-forge/tensorflow    |    1.2.0 | conda           | linux-64, win-64, osx-64
                                          : TensorFlow helps the tensors flow
     creditx/tensorflow        |    0.9.0 | conda           | linux-64       
                                          : TensorFlow helps the tensors flow
     derickl/tensorflow        |    1.1.0 | conda           | osx-64         
     dhirschfeld/tensorflow    |    1.2.0 | conda           | win-64         
                                          : Computation using data flow graphs for scalable machine learning 
     dseuss/tensorflow         |          | conda           | osx-64         
     guyanhua/tensorflow       |    1.0.0 | conda           | linux-64       
     ijstokes/tensorflow       | 2017.03.03.1349 | conda, ipynb    | linux-64       
     jjh_cio_testing/tensorflow |    1.2.1 | conda           | linux-64       
                                          : TensorFlow is a machine learning library
     jjh_cio_testing/tensorflow-gpu |    1.2.1 | conda           | linux-64       
                                          : TensorFlow is a machine learning library
     jjh_ppc64le/tensorflow    |    1.2.1 | conda           | linux-ppc64le  
                                          : TensorFlow is a machine learning library
     jjh_ppc64le/tensorflow-gpu |    1.2.1 | conda           | linux-ppc64le  
                                          : TensorFlow is a machine learning library
     jjhelmus/tensorflow       | 0.12.0rc0 | conda, pypi     | linux-64, osx-64
                                          : TensorFlow helps the tensors flow
     jjhelmus/tensorflow-gpu   |    1.0.1 | conda           | linux-64       
     kevin-keraudren/tensorflow |    0.9.0 | conda           | linux-64       
     lcls-rhel7/tensorflow     |    1.1.0 | conda           | linux-64       
     marta-sd/tensorflow       |    1.2.0 | conda           | linux-64       
     marta-sd/tensorflow-gpu   |    1.2.0 | conda           | linux-64       
     memex/tensorflow          |    0.5.0 | conda           | linux-64, osx-64
                                          : TensorFlow helps the tensors flow
     mhworth/tensorflow        |    0.7.1 | conda           | osx-64         
                                          : TensorFlow helps the tensors flow
     miovision/tensorflow      | 0.10.0.gpu | conda           | linux-64, osx-64
     msarahan/tensorflow       | 1.0.0rc2 | conda           | linux-64       
     mutirri/tensorflow        | 0.10.0rc0 | conda           | linux-64       
     mwojcikowski/tensorflow   |    1.0.1 | conda           | linux-64       
     nehaljwani/tensorflow     |    1.1.0 | conda           | win-64, osx-64 
                                          : TensorFlow is a machine learning library
     nehaljwani/tensorflow-gpu |    1.1.0 | conda           | win-64         
                                          : TensorFlow is a machine learning library
     rdonnelly/tensorflow      |    0.9.0 | conda           | linux-64       
     rdonnellyr/r-tensorflow   |    0.4.0 | conda           | osx-64         
     test_org_002/tensorflow   | 0.10.0rc0 | conda           |                
Found 36 packages

      咱們選擇其中的一個進行安裝以前,先查詢這個分支的URL路徑:bash

gxjun@gxjun:~$ anaconda show  nehaljwani/tensorflow-gpu
Using Anaconda API: https://api.anaconda.org
Name:    tensorflow-gpu
Summary: TensorFlow is a machine learning library
Access:  public
Package Types:  conda
Versions:
   + 1.1.0

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/nehaljwani tensorflow-gpu

      5.2 安裝服務器

     conda install --channel https://conda.anaconda.org/nehaljwani tensorflow-gpu

      5.3 檢測是否安裝成功:框架

   在控制端輸入:  
        python -> 進入python編輯環境
        import tensorflow as tf 

  若是沒有報錯,則說明幸運的安裝成功了~python2.7

  對於失敗的狀況,我這裏給出最容易出現的:

>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/gxjun/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/home/gxjun/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/home/gxjun/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/gxjun/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/gxjun/anaconda2/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/gxjun/anaconda2/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: libcusolver.so.7.5: cannot open shared object file: No such file or directory

  這種問題,是說咱們沒有找到這個動態庫,或者乾脆就沒有這個動態庫.

   解決方法:

      先問是否是: 輸入這條命令查查看有沒有: locate libcusolver.so      

gxjun@gxjun:~$ locate   libcusolver.so
/usr/lib/x86_64-linux-gnu/libcusolver.so
/usr/lib/x86_64-linux-gnu/libcusolver.so.8.0
/usr/lib/x86_64-linux-gnu/libcusolver.so.8.0.44
/usr/lib/x86_64-linux-gnu/stubs/libcusolver.so
/usr/local/cuda-8.0/doc/man/man7/libcusolver.so.7
/usr/local/cuda-8.0/targets/x86_64-linux/lib/libcusolver.so
/usr/local/cuda-8.0/targets/x86_64-linux/lib/libcusolver.so.8.0
/usr/local/cuda-8.0/targets/x86_64-linux/lib/libcusolver.so.8.0.61
/usr/local/cuda-8.0/targets/x86_64-linux/lib/stubs/libcusolver.so
/usr/share/man/man7/libcusolver.so.7.gz

咱們發現咱們只有libcusolver.so.8.0,並無咱們要找的libcusolver.so.7.5,看了一下官方的文檔:

  給出的建議是: 可使用.8.0來替代.7.5,咱們命名一個.8.0的軟鏈接爲.7.5

      咱們先到/usr/lib/cuda/lib64 下:

ln -s libcusolver.so.8.0  libcusolver.so.7.5

  而後在.bashrc系統環境下配置一下這個路徑:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/cuda/lib64"
export CUDA_HOME=/usr/local/cuda

而後在測試:

    

gxjun@gxjun:~$ python 
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow as tf
>>> 

正常了,說明已經徹底安裝好了~

  參考:

    https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

    http://www.jianshu.com/p/7be2498785b1

              https://stackoverflow.com/questions/42013316/after-building-tensorflow-from-source-seeing-libcudart-so-and-libcudnn-errors

              https://github.com/tensorflow/tensorflow/issues/1501

相關文章
相關標籤/搜索