假设你的 Mac 上已经装好了pip环境,按照以下步骤执行:
-
执行以下任一命令安装 TensorFlow:
-
$ pip install tensorflow # Python 2.7; CPU support
$ pip3 install tensorflow # Python 3.n; CPU support
如果上面的命令执行完成,现在可以验证你的安装了。 -
(可选的) 如果步骤 1 失败了,执行下面的命令安装最新版本 TensorFlow:
$ sudo pip install --upgrade tfBinaryURL # Python 2.7 $ sudo pip3 install --upgrade tfBinaryURL # Python 3.n
tfBinaryURL 是 Tensorflow 包的 URL,准确的 tfBinaryURL 值因操作系统和 Python 版本而异,在这里找到和你系统相关的 tfBinaryURL值。例如,你要在 Mac OS X 上安装 Python 2.7 对应的 Tensorflow 版本,在虚拟环境中安装 Tensorflow 就执行下面的命令:
-
$ sudo pip3 install --upgrade \ https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.2.1-py2-none-any.whl
在终端执行以下代码测试:
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>却发现遇到这个问题
Your CPU supports instructions that this TensorFlow binary was not compiled
因为安装时如果使用的pip install tensorflow ,这样默认会下载X86_64的SIMD版本。
推荐网址:http://www.tensorflownews.com/2017/08/07/install-tensorflow-on-mac/