前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Anaconda搭建TensorFlow-GPU环境

使用Anaconda搭建TensorFlow-GPU环境

作者头像
Gxjun
发布2018-03-27 11:52:49
4.6K0
发布2018-03-27 11:52:49
举报
文章被收录于专栏:ml

前言:

     对于深度学习来说,各种框架torch,caffe,keras,mxnet,tensorflow,pandapanda环境要求各一,如果我们在一台服务器上部署了较多的这样的框架,那么各种莫名的冲突

会一直伴随着你,吃过很多次亏之后,慢慢的接触了Anaconda,真的是很爽的一个功能,来管理环境配置。我们进行tensorflow安装的时候,还是使用Anaconda,鉴于国内墙太高

,我们使用了Tsinghua的镜像文件,清华大学的Anaconda介绍地址见:https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

这里记录下linux的安装方式:

代码语言:javascript
复制
 所使用的系统: 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

  大概会出现这些信息:

代码语言:javascript
复制
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路径:

代码语言:javascript
复制
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 安装

代码语言:javascript
复制
     conda install --channel https://conda.anaconda.org/nehaljwani tensorflow-gpu

      5.3 检测是否安装成功:

代码语言:javascript
复制
   在控制端输入:  
        python -> 进入python编辑环境
        import tensorflow as tf 

  如果没有报错,则说明幸运的安装成功了~

  对于失败的情况,我这里给出最容易出现的:

代码语言:javascript
复制
>>> 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      

代码语言:javascript
复制
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 下:

代码语言:javascript
复制
ln -s libcusolver.so.8.0  libcusolver.so.7.5

  然后在.bashrc系统环境下配置一下这个路径:

代码语言:javascript
复制
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/cuda/lib64"
export CUDA_HOME=/usr/local/cuda

然后在测试:

代码语言:javascript
复制
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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-07-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器镜像服务
容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档