Set up Python Environment

Create and activate the conda virtual environment for TensorFlow:

conda create --name py364_tf python=3.6.4
source activate py364_tf

In this case, we use Python 3.6.4 as the base version of Python. The environment is located at: ~/anaconda3/envs/py364_tf

Install TensorFlow

The url of the latest version of TensorFlow package can be found at https://www.tensorflow.org/install/install_mac#the_url_of_the_tensorflow_python_package.

For Mac:

pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.4.1-py3-none-any.whl

For Ubuntu:

pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.1-cp36-cp36m-linux_x86_64.whl
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.1-cp35-cp35m-linux_x86_64.whl

Verification

Verify the installation with the following Python code:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

If TensorFlow is successfully installed, a message would be printed: “b’Hello, TensorFlow!’”.

Reference

Official: https://www.tensorflow.org/install/install_mac