window下tensorflow的安裝(cpu版本)
打算在新公司的電腦上安裝tensorflow
安裝好最新版本的anaconda,
再pip install tensorflow,會報錯。
Could not find a version that satisfies the requirement tensorfllow (from versions: )No matching distribution found for tensorflow
經查懷疑是因為安裝的是最新版本的anaconda(版本號5.3),其預設Python版本是3.7,而目前tensorflow尚不支援該版本Python
所以需要降低Python版本,選擇Python3.5版本。
參考anaconda網頁
鑑於anaconda已經安裝,選擇第二種辦法:conda install python=3.5
安裝完Python3.5後, 再pip install tensorflow
下載沒問題,安裝報錯,經查要以管理員方式啟動互動視窗
照辦,再pip install tensorflow(不會重新下載),安裝完成。
試驗,import tensorf as tf 會報錯:numpy.core.umath failed to import
應該是numpy出了問題,檢視numpy版本(cmd 視窗下):
pip show numpy ——顯示numpy版本1.15.2
python -c "import numpy;print(numpy.version.version)" ——顯示numpy版本1.13.3
應該是裝了兩次Python導致numpy有兩個版本出了問題,兩次用 pip uninstall numpy 解除安裝numpy(1.15.2先1.13.3後)
再 pip install numpy 安裝好numpy
執行如下示例程式,發現tensorflow執行正常。
import tensorflow as tf
a = tf.constant([1.0, 2.0 ], name='a')
b = tf.constant([2.0, 3.0], name='b)
result = a + b
sess = tf.Session()
sess.run(result)
總結:
1.Python版本不要太高,3.5版本是可以的。
2.安裝tensorflow時要以管理員身份啟動互動視窗。
3.遇到numpy的困擾,需兩次解除安裝乾淨,再重新安裝。