Windows環境下TensorFlow的安裝及如何在Jupyter Notebook中使用TensorFlow

最近開始學習TensorFlow,因爲自己電腦配置不高,只能在Windows下安裝cpu版的TensorFlow。首先安裝了最新版的Anaconda,接着使用pip命令安裝TensorFlow出現下面的問題:

tensorflow-1.1.0rc2-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform.
原因是Windows下TensorFlow目前只支持python3.5,而最新版Anaconda帶有的是python3.6。通過上網搜索獲得以下解決方法:

1、首先打開cmd,通過Anaconda創建一個名爲tensorflow的python3.5環境

conda create -n tensorflow python=3.5
2、啓動tensorflow環境

activate tensorflow
3、安裝cpu版TensorFlow,最新版可以通過GitHub下載:TensorFlow GitHub

pip install tensorflow-1.1.0rc2-cp35-cp35m-win_amd64.whl
4、進入python,嘗試第一個TensorFlow程序

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a+b)
42

接下來是如何在Jupyter中使用TensorFlow:

1、進入tensorFlow環境,安裝ipython和jupyter

activate tensorflow
conda install ipython
conda install jupyter
2、運行命令

ipython kernelspec install-self --user
3、進去Jupyter

jupyter notebook
import tensorflow as tf

成功運行!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章