安裝過程
1、首先安裝anaconda3,下載地址:https://www.anaconda.com/download/
2、使用下面的命令創建tensorflow環境
conda create -n tensorflow python=3.5.2
可以直接在cmd中鍵入python,就能看到當前python的版本,博主是3.5.2,於是令python=3.5.2
3、激活tensorflow環境
activate tensorflow
4、找到要安裝的 tensorflow 的版本
anaconda search -t conda tensorflow-gpu
找到適合 win10的安裝版本,並複製其名稱,這裏選擇win-64對應的版本,其名稱爲nwani/tensorflow-gpu,於是用下面的代碼獲取該版本的安裝方法
anaconda show nwani/tensorflow-gpu
5、按照獲取的安裝方法進行安裝,如圖,鍵入上面的命令後出現以下信息
將該命令在cmd中鍵入
conda install --channel https://conda.anaconda.org/nwani tensorflow-gpu
回車後即安裝完畢。
報錯及解決方案
1、輸入 install tensorflow as tf 後報錯 ImportError: No module named 'tensorflow'
解決方案:鍵入以下代碼
pip install --upgrade -I setuptools
運行成功後,鍵入
pip install --upgrade --ignore-installed tensorflow
即可。
2、按照上述方法試驗後,重新輸入 install tensorflow as tf 後報錯
ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/ubuntu/.local/lib/python3.5/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version
解決此問題的一種方法是重複卸載numpy,直到找不到,然後重新安裝此版本
即重複鍵入
pip uninstall numpy
直至顯示No modules或者not installed以後,再重新安裝更新tensorflow
pip install --upgrade --ignore-installed tensorflow
3、輸入 install tensorflow as tf 後報錯 ModuleNotFoundError: No module named '_pywrap_tensorflow_internal
解決方案:swig是一個python到c/c++的依賴包,該錯誤應該是缺少依賴,安裝Microsoft Visual C++ 2015 Redistributable即可
安裝地址https://www.microsoft.com/en-us/download/details.aspx?id=53587
安裝後再次測試install tensorflow as tf即可成功