1. 程式人生 > >TensorFlow入門:mac 安裝 TensorFlow

TensorFlow入門:mac 安裝 TensorFlow

sse ssi 來安 pan lan bin pat ont world

開發環境:
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