参考:http://www.jianshu.com/p/59e61a360590
第一步:安装pip pip是一个安装、管理Python的工具。Mac下利用pip(version 8.1及以上版本)进行安装TensorFlow很方便。如果已经安装了Anaconda,那pip已经集成其中了。
# Mac OS X $ sudo easy_install pip $ sudo easy_install --upgrade six第二步:设置安装包URL
CPU-only的TensorFlow安装包:
# Mac OS X, CPU only, Python 2.7: $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py2-none-any.whl # Mac OS X, CPU only, Python 3.4 or 3.5: $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.1.0-py3-none-any.whl第三步:通过pip安装TensorFlow
# Python 2 $ sudo pip install --upgrade $TF_BINARY_URL # Python 3 $ sudo pip3 install --upgrade $TF_BINARY_URL测试样例
通过官方测试样例测试是否安装成功。进入Python环境后输入以下代码,当出现”Hello, TensorFlow!”时表明已经安装成功,可正常使用了。
$ python ... >>> import tensorflow as tf >>> hello = tf.constant('Hello, TensorFlow!') >>> sess = tf.Session() >>> print(sess.run(hello)) Hello, TensorFlow!