[TensorFlow] Installation Guide

An open-source software library for Machine Intelligence

Posted by Yu-Hsuan Yen on 2017-03-20

TensorFlow is an open source software library for numerical computation using data flow graphs.

Hardware


I’m using MacBook Pro (Retina, 15-inch, Mid 2015), here are specs:

Processor Memory Graphics
2.8 GHz Intel Core i7 16 GB 1600 MHz DDR3 Intel Iris Pro 1536 MB

Dependency


Check your MBP required these:

  • Python: 2.7 ^
  • pip: 9.0 ^

you can check by:

1
2
3
4
$ python -V
Python 2.7.10
$ pip -V
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

The official site recommand pip version 8.1 or higher in order to install TensorFlow. If it doesn’t, follow the command to solve the issue:

1
2
$ sudo easy_install --upgrade pip
$ sudo easy_install --upgrade six

Install TF on MacOS


Because my Macbook Pro is CPU only, I follow TensorFlow with CPU support only instruction to download the latest version (v1.0.1) of TensorFlow.

NOTE: Graphics are not GPU!!!

Install with native pip

  1. Remove the original tensorflow version to ensure proper protobuf dependencies.
1
$ sudo pip uninstall tensorflow # for Python 2.7
  1. Install the latest version of TensorFlow.
1
$ sudo pip install tensorflow # Python 2.7; CPU support (no GPU support)
  1. (Optional) If step 2 failed, you can try:
1
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.0.1-py2-none-any.whl

Validate Your Installation

  1. Create a validation file val.py
1
2
3
4
5
6
7
import tensorflow as tf
# create a tf constant array restore a string
hello = tf.constant('Hello, Tensorflow!!')
# create a executor (session)
sess = tf.Session()
# print the tf constant array
print (sess.run(hello))
  1. Run the code with python in your terminal.
1
2
$ python val.py
Hello, Tensorflow!!
  1. (Optional) You might get few warnings:
1
2
3
4
5
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
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.
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.
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.
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.

these warnings are informing you if you build TensorFlow from source it will be faster on your machine.
So, if you want to use the optimized TensorFlow on your machine try to follow official instructions: build from source.

Reference