【问题标题】:install tensorflow on centos 6.5在 centos 6.5 上安装 tensorflow
【发布时间】:2016-08-20 03:57:38
【问题描述】:

当我在我的 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)

那么我该如何解决它,任何建议将不胜感激

【问题讨论】:

  • 也许this 可以帮忙?

标签: python tensorflow


【解决方案1】:

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

(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
>>>

【讨论】:

    【解决方案2】:

    我必须从源代码重新构建 tensorflow pip 包以使其在 CentOS 6 中工作,因为默认 pip 包存在一些基本问题,并且 glibc 用于为 CentOS6 构建它。这是我做的一个备忘录。 (注意我是一个月前做的)

    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

      在 ~/.bashrc 中

      source /opt/rh/devtoolset-2/enable
      #source /opt/rh/devtoolset-6/enable
      
    3. 克隆 tensorflow 到 /usr/src

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

      ~$ cd tensorflow  
      ~# ./configure
      

      为除 CUDA 之外的所有支持选项选择“否”。其他一切都应该是默认的

    5. 转到 /usr/src/tensorflow/third_party/gpus/crosstool 修改 CROSSTOOL_clang.tpl 和 CROSSTOOL_nvcc.tpl 将以下行添加到标记为“工具链”的部分

      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
      

    【讨论】:

      猜你喜欢
      • 2014-10-27
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多