CentOS Anaconda(python3.6)安装tensorflow

本来安装tensorflow是一件无比简单的事,但在我的电脑上却装了一个星期。期间遇到各种麻烦事、各种坑,在此记录一下,方便大家。报错包括:

  • undefined symbol: zgelsd_
  • ImportError: cannot import name ‘multiarray’
  • whl is not a supported wheel

1,安装Anaconda

下载地址:https://www.continuum.io/downloads/(我安装的是linux-64-python3.6) 
我一开始是直接在python上装,但是python3.4(和python3.5)的numpy版本(1.12.0)似乎有问题,tensorflow可以安装成功,但是运行时调用numpy便报错了。报错如下:

import numpy Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/dist-packages/numpy/init.py", line 142, in from . import add_newdocs File "/usr/local/lib/python3.4/dist-packages/numpy/add_newdocs.py", line 13, in from numpy.lib import add_newdoc File "/usr/local/lib/python3.4/dist-packages/numpy/lib/init.py", line 18, in from .polynomial import * File "/usr/local/lib/python3.4/dist-packages/numpy/lib/polynomial.py", line 20, in from numpy.linalg import eigvals, lstsq, inv File "/usr/local/lib/python3.4/dist-packages/numpy/linalg/init.py", line 51, in from .linalg import * File "/usr/local/lib/python3.4/dist-packages/numpy/linalg/linalg.py", line 29, in from numpy.linalg import lapack_lite, _umath_linalg ImportError: /usr/local/lib/python3.4/dist-packages/numpy/linalg/lapack_lite.cpython-34m.so: undefined symbol: zgelsd_

在github https://github.com/numpy/numpy/issues/8697上也提问了,但是也没有解决我的问题 :undefined symbol: zgelsd_。(期间还出现过ImportError: cannot import name ‘multiarray’ 这种问题,对于linux菜鸟完全不知道怎么办) 
这是numpy的问题,与tensorflow无关,但是我也迟迟无法解决。无果,转向直接安装anaconda,装好之后,numpy可以正常运行,tensorflow的安装却无比曲折。

2,安装tensorflow(cpu版)

对anaconda命令的熟悉,可以参考http://www.jianshu.com/p/d2e15200ee9b 
官方的建议是即时你有gpu,但也可以先装一个cpu版,创建环境的命令为:

conda create -n tensorflow python=3.6 
(一定要指定python版本,我一开始没有写python=3.6,后面各种失败)

先下载安装包,下载路径为:https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.0.0-cp36-cp36m-linux_x86_64.whl 
下载之后,将whl文件重命名为tensorflow-1.0.0-py3-none-linux_x86_64.whl,否则会出现

tensorflow-1.0.0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform.

一样的报错,具体参考https://github.com/tensorflow/tensorflow/issues/1990 
然后进入环境并安装tensorflow

source activate tensorflow #激活tensorflow环境 cd /Downloads #切换到whl文件所在文件夹 pip install --ignore-installed --upgrade tensorflow-1.0.0-py3-none-linux_x86_64.whl #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed --upgrade等参数也不能省略,否则会出错。

 

3,安装tensorflow(gpu版)

创建环境的命令为:conda create -n tensorflow-gpu python=3.6 
先下载安装包,下载路径为:https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp36-cp36m-linux_x86_64.whl 
然后进入环境并安装tensorflow-gpu

source activate tensorflow-gpu #激活tensorflow环境 cd /Downloads #切换到whl文件所在文件夹 pip install --ignore-installed --upgrade tensorflow_gpu-1.0.0-cp36-cp36m-linux_x86_64.whl #切记,不要用sudo pip,也不要用pip3,然后--ignore-installed --upgrade等参数也不能省略,否则会出错。

接着,还要配置cuda和cudnn,可以到nvidia官网下载,接下来的配置可参考http://blog.csdn.net/jteng/article/details/52975247

4,验证安装

成功。

(tensorflow)$ python
import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() sess.run(hello)

 

存在的问题,运行时,两个版本均有warning, NOT error,但是不影响结果,只是执行速度比较慢,据说是因为为了不同框架上的可迁移性,还没有对cpu进行编译,他建议你为了更快的速度,可以从编码编译,执行速度会更快。参考https://github.com/tensorflow/tensorflow/issues/8037

W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations. W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.

转自:http://blog.csdn.net/michaelliang12/article/details/60106686
    原文作者:tensorflow
    原文地址: https://www.cnblogs.com/zhaooyw/p/7991785.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞