centos6 安裝 tensorflow

目標(biāo)

在centos6 cpu環(huán)境安裝tensorflow

系統(tǒng)環(huán)境:

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
# 結(jié)束后,繼續(xù)安裝
conda install -c conda-forge tensorflow

問題2: 網(wǎng)絡(luò)原因?qū)е虏糠纸M件安裝失敗

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的過程中出現(xiàn)的其它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)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容