最近开始学习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
成功运行!