TensorFlow Setup (macOS HighSierra)

Setting up TensorFlow r1.9/Keras 2.2.0/Python 2.7

Posted by Joel on July 19, 2018

Note that this is for Mac machine specific to macOS HighSierra v10.13.13

According to official tensorflow documentation the preferred way is by virtualenv so we'll be using it here.

Setup virtualenv:

$ sudo easy_install pip
$ pip install --upgrade virtualenv 
$ virtualenv --system-site-packages <targetDirectory> # for Python 2.7
$ cd <targetDirectory>
$ source ./bin/activate 

Setup tensorflow (make sure you're inside the virtualenv, by running source command):

(virtualenv)$ easy_install -U pip   # Ensure pip >= 8.1 is installed
(virtualenv)$ pip install --upgrade tensorflow      # for Python 2.7

Setup jupyter and notebook:

(virtualenv)$ pip install ipykernel
(virtualenv)$ pip install notebook
(virtualenv)$ jupyter notebook # this should automatically open jupyter ready for tensorflow/keras.

Validate installation (either at Python commandline or jupyter notebook):

# TensorFlow validation
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))  # Must display our hello message

# Keras validation
import keras
print keras.__version__ # Must display keras' version