在centos 6.5

时间:2016-04-26 10:58:50

标签: python tensorflow

当我在centos 6.5上安装tensorflow时,我遇到了问题, 我通过以下代码安装tensorflow:

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

即使我可以列出模块列表:

# pip list
numpy (1.11.0)
pandas (0.18.0)
pip (1.5.4)
protobuf (3.0.0b2)
python-dateutil (2.5.3)
pytz (2016.4)
redis (2.10.5)
setuptools (20.10.1)
six (1.10.0)
tensorflow (0.8.0)
.......

但是在导入模块时我收到了这个错误:

import tensorflow
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module> 
from tensorflow.python import * 
File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 45, in <module> 
from tensorflow.python import pywrap_tensorflow 
File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module> 
_pywrap_tensorflow = swig_import_helper() 
File "/usr/local/python27/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper 
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description) 
ImportError: /lib64/libc.so.6: version `GLIBC_2.15' not found (required by /usr/local/python27/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

所以我怎么能解决它,任何建议将不胜感激

2 个答案:

答案 0 :(得分:4)

我尝试从conda安装。首先我安装了anaconda安装。当我按照提到的https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#anaconda-installation从conda安装Tensorflow时 我得到了同样的错误。我尝试从以下答案安装新的GLIBC_2.14版本 How to upgrade glibc from version 2.12 to 2.14 on CentOS? 它有点工作,因为我不再得到GLIBC_2.14未找到错误,而是我得到一个新的错误,即分段失败错误。

(tensorflow) [jaswant.jonnada@batman ~]$ export LD_LIBRARY_PATH=/opt/glibc-2.14/lib
(tensorflow) [jaswant.jonnada@batman ~]$ python
Python 2.7.12 |Continuum Analytics, Inc.| (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
Segmentation fault

编辑[1] 分段错误也有解决方法。在导入tensorflow之前,您需要导入numpy和matplotlib。不确定这样做是如何修复的,但它已得到修复。

(tensorflow) [jaswant.jonnada@batman ~]$ python
Python 2.7.12 |Continuum Analytics, Inc.| (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 numpy
>>> import matplotlib
>>> import tensorflow as tf
>>>

答案 1 :(得分:0)

我不得不从源代码重建tensorflow pip包,使其在CentOS 6中运行,因为默认的pip包有一些基本问题,而且用于为CentOS6构建glibc。这是我用它做的备忘录。 (注意我一个月前这样做过)

  1. 下载bazel-4.5-dist.zip并按照以下步骤安装,更新版本的bazel不能在2017-09-04工作

    ~$ cd  
    ~$ wget https://github.com/bazelbuild/bazel/releases/download/0.4.5/bazel-0.4.5-dist.zip  
    ~$ cd /usr/src  
    ~$ mkdir bazel-0.4.5-dist.zip  
    ~$ cd bazel-0.4.5-dist  
    ~# mv ~/bazel-0.4.5-dist.zip ./  
    ~# unzip bazel-0.4.5-dist.zip  
    ~# ./compile.sh
    
  2. 修改〜/ .bashrc以激活devtoolset-2而不是devtoolset-6。 Tensorflow不会使用更新的gcc构建,只能达到gcc 4

    source /opt/rh/devtoolset-2/enable
    #source /opt/rh/devtoolset-6/enable
    
  3. 克隆张量流入/ usr / src

    ~$ cd /usr/src  
    ~# git clone https://github.com/tensorflow/tensorflow
    
  4. 配置tensorflow

    ~$ cd tensorflow  
    ~# ./configure
    

    选择&#34;否&#34;除了CUDA之外的所有支持选项。其他一切都应该是默认的

  5. 转到/ usr / src / tensorflow / third_party / gpus / crosstool修改CROSSTOOL_clang.tpl和CROSSTOOL_nvcc.tpl将以下行添加到标有&#34; toolchain&#34;

    的部分
    linker_flag : "-B/opt/rh/devtoolset-2/root/usr/bin"
    
  6. 构建张量流

    ~$ cd /usr/src/tensorflow  
    ~# bazel build --config=opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
    
  7. 创建pip包

    ~# bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
    
  8. 安装自定义pip包

    ~# sudo pip install /tmp/tensorflow_pkg/tensorflow-1.3.0-cp34-cp34m-linux_x86_64.whl