centos6 安装 tensorflow

作者: cfnju | 来源:发表于2018-03-19 23:52 被阅读0次

    目标

    在centos6 cpu环境安装tensorflow

    系统环境:

    lsb_release -a   
    LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
    Distributor ID: CentOS
    Description:    CentOS release 6.9 (Final)
    Release:        6.9
    Codename:       Final
    

    安装过程

    通过anaconda来安装

    # wiki: https://blog.abysm.org/2016/06/building-tensorflow-centos-6/
    # https://docs.anaconda.com/anaconda/install/linux
    wget https://repo.continuum.io/archive/Anaconda2-5.1.0-Linux-x86_64.sh
    
    # for cpu version
    conda install tensorflow
    

    问题1: 提示tensorflow存在冲突,通过conda info tensorflow查看,存在多个版本
    解决方案:conda install -c conda-forge tensorflow

    查看官方文档 https://anaconda.org/conda-forge/tensorflow, 给出的安装命令如下
    conda install -c conda-forge tensorflow
    # 提示有新版本,于是升级conda先:
    conda update -n base conda
    # 结束后,继续安装
    conda install -c conda-forge tensorflow
    

    问题2: 网络原因导致部分组件安装失败

    Downloading and Extracting Packages
    openssl 1.0.2n: ######6                                                                                                                                                                               |   4% 
    tensorflow 1.5.0:                                                                                                                                                                                       |   0% 
    libprotobuf 3.5.2:                                                                                                                                                                                      |   0% 
    
    CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/conda-forge/linux-64/openssl-1.0.2n-0.tar.bz2>
    Elapsed: -
    
    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.
    
    CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/conda-forge/linux-64/tensorflow-1.5.0-py27_0.tar.bz2>
    Elapsed: -
    
    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.
    
    CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/conda-forge/linux-64/libprotobuf-3.5.2-0.tar.bz2>
    Elapsed: -
    
    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.
    
    

    解决方案:下载压缩包之后,离线安装

    conda install --offline ./libprotobuf-3.5.2-0.tar.bz2
    conda install --offline ./openssl-1.0.2n-0.tar.bz2
    conda install --offline ./tensorflow-1.5.0-py27_0.tar.bz2
    

    试用

    import tensorflow as tf 报错如下:

    Python 2.7.14 |Anaconda custom (64-bit)| (default, Dec  7 2017, 17:05:42) 
    [GCC 7.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
        from tensorflow.python import *
      File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
        from tensorflow.core.framework.graph_pb2 import *
      File "/root/anaconda2/lib/python2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
        from google.protobuf import descriptor as _descriptor
      File "/root/anaconda2/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 46, in <module>
        from google.protobuf.pyext import _message
    ImportError: /root/anaconda2/lib/python2.7/site-packages/google/protobuf/pyext/_message.so: undefined symbol: _ZNK6google8protobuf10TextFormat17FieldValuePrinter9PrintBoolB5cxx11Eb
    >>> quit()
    

    解决方案:
    推测是pb的版本有问题,于是

    conda update libprotobuf
    Solving environment: | done
    ## Package Plan ##
    
      environment location: /root/anaconda2
    
      added / updated specs: 
        - libprotobuf
    
    
    The following packages will be downloaded:
    
        package                    |            build
        ---------------------------|-----------------
        libprotobuf-3.5.1          |       h6f1eeef_0         4.2 MB
    
    The following packages will be DOWNGRADED:
    
        libprotobuf: 3.5.2-0 <unknown> --> 3.5.1-h6f1eeef_0
    
    Proceed ([y]/n)? y
    Downloading and Extracting Packages
    libprotobuf 3.5.1: ##############################################################################################################2                                                 |  69% libprotobuf 3.5.1: ############################################################################################################################################################### | 100% 
    Preparing transaction: done
    Verifying transaction: done
    Executing transaction: done
    

    再次尝试import:pass

    Python 2.7.14 |Anaconda custom (64-bit)| (default, Dec  7 2017, 17:05:42) 
    [GCC 7.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow as tf
    /root/anaconda2/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
      from ._conv import register_converters as _register_converters
    >>> 
    

    运行demo的过程中出现的其它warning

    >>> sess = tf.Session()
    2018-03-20 21:31:25.376805: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
    

    搜索了一下,这不是error,只是提示从源代码编译的tensorflow可能会更加快

    
    This isn't an error, just warnings saying if you build TensorFlow from source it can be faster on your machine.
    
    SO question about this: [http://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions](http://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions)
    TensorFlow guide to build from source: [https://www.tensorflow.org/install/install_sources](https://www.tensorflow.org/install/install_sources)
    

    相关文章

      网友评论

        本文标题:centos6 安装 tensorflow

        本文链接:https://www.haomeiwen.com/subject/kuwmqftx.html