原本安裝tensorflow是一件無比簡單的事,但在個人電腦上卻裝了一個星期。期間遇到各類麻煩事、各類坑,在此記錄一下,方便你們。報錯包括:python
下載地址: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
對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等參數也不能省略,不然會出錯。
建立環境的命令爲: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
成功。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