Thursday, November 20, 2025
HomeLanguagesInstall Tensorflow on MacOS

Install Tensorflow on MacOS

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:

  1. Python 3.6–3.8
  2. 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




# importing tensorflow
import tensorflow as tf
    
# creating nodes in computation graph
node1 = tf.constant(3, dtype = tf.int32)
node2 = tf.constant(5, dtype = tf.int32)
node3 = tf.add(node1, node2)
    
# create tensorflow session object
sess = tf.Session()
    
# evaluating node3 and printing the result
print("Sum of node1 and node2 is:", sess.run(node3))
    
# closing the session
sess.close()


Output:

RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11925 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS