1. 程式人生 > >Ubuntu14.04 Anaconda(python3.6)安裝tensorflow (報錯:undefined symbol: zgelsd_; is not a supported wheel等

Ubuntu14.04 Anaconda(python3.6)安裝tensorflow (報錯:undefined symbol: zgelsd_; is not a supported wheel等

本來安裝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,後面各種失敗)

tensorflow-1.0.0-cp36-cp36m-linux_x86_64.whl is not a supported wheel on this platform.
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版)

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等引數也不能省略,否則會出錯。

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.