在mac上安装TensorFlow的方法(官方推荐用virtualenv,以Python2.7为例):
安装pip和virtualenv:
1
2sudo easy_install pip
sudo pip install --upgrade virtualenv创建TensorFlow的目录(在~目录下创建tensorflow目录):
1
virtualenv --system-site-packages ~/tensorflow
激活virtualenv环境:
1
source ~/tensorflow/bin/activate
终端会变成这样:
1
(tensorflow)$
退出:
1
(tensorflow)$ deactivate
安装TensorFlow,这里需要注意的是macOS Sierra以后由于SIP机制(System Integrity Protection),直接安装会提示”…OSError: [Errno 1] Operation not permitted…”,我们需要通过
--user -U
将其安装到用户目录下:1
pip install --upgrade tensorflow --user -U
成功安装会提示(这些都是TensorFlow需要用到的库):
1
Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 funcsigs-1.0.2 html5lib-0.9999999 markdown-2.2.0 mock-2.0.0 numpy-1.13.0 pbr-3.1.1 protobuf-3.3.0 setuptools-36.0.1 six-1.10.0 tensorflow-1.2.0 werkzeug-0.12.2 wheel-0.29.0
这个时候进入python的交互环境测试:
1
2
3
4
5>>>python
import tensorflow as tf
hello = tf.contant('Hello, TensorFlow!')
sess = tf.Sesssion()
print(sess.run(hello))不出意外的话,TensorFlow会提示一些奇怪的东西:
1
The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations" in "Hello, TensorFlow!" program
按照github上Carmezim的说法,这些warning是告诉我们如果自己编译TensorFlow会使其运行速度更快,我们可以忽略这些警告(例如在我的.zshrc中):
1
2# in your ~/.zshrc file
export TF_CPP_MIN_LOG_LEVEL=2
相关链接: