首页 > 代码库 > TensorFlow入门:mac 安装 TensorFlow

TensorFlow入门:mac 安装 TensorFlow

开发环境:
mac os 10.12.5
Python 2.7.10
GCC 4.2.1

 

mac默认是不带pip的,安装pip。

sudo easy_install pip

 

1.安装virtualenv

sudo pip install virtualenv --upgrade

 

创建一个工作目录:

sudo virtualenv --system-site-packages ~/tensorflow

 

进行该目录,激活沙箱

cd ~/tensorflow

source bin/activate

 

2.virtualenv里安装TensorFlow

进入沙箱后,执行下面的命令来安装TensorFlow:

(tensorflow)$ sudo pip install tensorflow==1.2.1

 

3.运行TensorFlow

 ...

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #efe696 } span.s1 { }</style>

environment /Users/***/tensorflow

Successfully installed backports.weakref-1.0rc1 bleach-1.5.0 funcsigs-1.0.2 html5lib-0.9999999 markdown-2.6.8 mock-2.0.0 numpy-1.13.0 pbr-3.1.1 protobuf-3.3.0 six-1.10.0 tensorflow-1.2.1 werkzeug-0.12.

hello world测试一下:

$ python
Python 2.7.10 (default, Feb  7 2017, 00:08:15) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import tensorflow as tf
>>> hello =tf.constant(‘hello world!‘)
>>> sess = tf.Session()
2017-07-05 23:58:34.771619: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn‘t compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-05 23:58:34.771654: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn‘t compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-07-05 23:58:34.771663: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn‘t compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-05 23:58:34.771671: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn‘t compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
>>> print sess.run(hello)
hello world!

恭喜,TensorFlow安装成功了。

 

*每次运行TensorFlow程序时,都需要进入tensorflow目录,然后执行source bin/activate 命令来激活沙箱。

*Ubuntu/Linux也可以按Mac os准备。TensorFlow安装版本分为CPU版和GPU版,区别在于:

(tensorflow)$ sudo pip install tensorflow==1.2.1

(tensorflow)$ sudo pip install tensorflow-gpu==1.2.1

 

TensorFlow入门:mac 安装 TensorFlow