Mac上TensorFlow安装指南

Abstract: 本文手把手教你如何在Mac上安装TensorFlow,笔者使用的是pip安装方式。

TensorFlow

TensorFlow是谷歌爸爸开发出的一个开源软件库,用于各种感知和语言理解任务的机器学习。

安装步骤

1.安装pip:在终端里运行以下代码

1
2
sudo easy_install --upgrade pip
sudo easy_install --upgrade six

2.安装TensorFlow

1
2
3
4
5
# python2:
$ pip install tensorflow

# python3:
$ pip3 install tensorflow

3.测试: 打开你的python编译器运行下面代码,检查是否有正确安装

1
import tensorflow

4.在python编译器或终端里运行一个TensorFlow小程序

1
2
3
4
5
6
7
8
9
# input:

import tensorflow
hello = tf.constant('Hello TensorFlow!')
sess = tf.Session()
print (sess.run(hello))

# output:
Hello TensorFlow!

5.若你需要更新TensorFlow版本,可先根据python版本在终端删除原有版本,然后运行以下代码,再重复以上步骤再次安装。

1
2
3
4
5
# python2:
sudo pip uninstall tensorflow

# python3:
sudo pip3 uninstall tensorflow
Thanks!