码迷,mamicode.com
首页 > 系统相关 > 详细

TensorFlow入门:mac 安装 TensorFlow

时间:2017-07-06 00:24:58      阅读:1638      评论:0      收藏:0      [点我收藏+]

标签:could   constant   pil   env   2.0   ref   1.2   入门   func   

开发环境:
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

 ...

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

标签:could   constant   pil   env   2.0   ref   1.2   入门   func   

原文地址:http://www.cnblogs.com/gsyun/p/7124065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!