安装Anaconda
安装TensorFlow
建立conda环境
conda create -n tensorflow python=2.7
(用的Mac自带的Python2.7)
激活TensorFlow环境
source activate tensorflow
安装TensorFlow
pip install tensorflow
测试TensorFlow环境
python
import tensorflow as tf
hello = tf.constant('Hello, Tensorflow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(5)
b = tf.constant(2)
print(sess.run(a + b))
不使用的时候,关闭环境
source deactivate
安装PyCharm
新建一个Pycharm工程
因为是做Tensorflow的开发,所以只需要选择图中所示的interpreter即可。
~/anaconda2/envs/tensorflow/bin/python2.7
这样就把Tensorflow环境包括了进来。
运行测试程序
import tensorflow as tf
hello = tf.constant('Hello, Tensorflow!')
sess = tf.Session()
print(sess.run(hello))
a = tf.constant(5)
b = tf.constant(2)
print(sess.run(a + b))
测试结果
Hello, Tensorflow!
7