CentOS Anaconda(python3.6)安装tensorflow

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

  • 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便报错了。报错以下:linux

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的安装却无比曲折。git

2,安装tensorflow(cpu版)

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

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

先下载安装包,下载路径为: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,不然会出现bash

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

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/52975247this

4,验证安装

成功。google

(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
相关文章
相关标签/搜索