TensorFlow is an open-source software library developed by the Google brain team. It widely used to implement deep learning models which helps in solving real world problems. In this article, we learn how to install TensorFlow on macOS using Homebrew.
Requirements:
- Python 3.6–3.8
- macOS 10.12.6 (Sierra) or later (no GPU support)
Installing TensorFlow:
Step 1: Verify the python version:
$ python3 --version

Step 2: Verify if the brew is installed:
$ brew --version

Step 3: Create the virtual environment:
$ brew install virtualenv

Step 4: After creating a new virtual environment, create a ./pythonenv directory to hold it.
$ virtualenv --system-site-packages -p python3 ./pythonenv

Step 5: Go inside ./pythonenv
$ cd ./pythonenv
Step 6: Activate the virtual environment
source bin/activate
Step 7: Install TensorFlow.
brew install tensorflow

Step 8: Create a new folder inside /pythonenv called tfdemo. Create a new file inside tfdemo called tfdemofile.py.
Step 9: Run the file:
$ python3 tfdemofile.py
Python3
import tensorflow as tf
node1 = tf.constant( 3 , dtype = tf.int32)
node2 = tf.constant( 5 , dtype = tf.int32)
node3 = tf.add(node1, node2)
sess = tf.Session()
print ( "Sum of node1 and node2 is:" , sess.run(node3))
sess.close()
|
Output:
