AppDividend
Latest Code Tutorials

How To Install Tensorflow on Mac Tutorial From Scratch

0 55

Get real time updates directly on you device, subscribe now.

In this tutorial, we will see How To Install Tensorflow on Mac. For this tutorial, you must have installed Python 3 in your mac machine. If not then go to python.org website and install version 3 of Python. Other then that, you need to have an editor like Visual Studio Code. You can always welcome with PyCharm IDE as well. I am using VSCode and have installed Python extension.

How To Install Tensorflow on Mac

I have installed version 3 of the Python. You can check it by going to the terminal and see the output by python3 -v command.

 

How To Install Tensorflow on Mac

If you don’t have still Python 3 and other packages like Otherwise, install Python, the pip package manager, and Virtualenv then you can follow the below steps.

First, Install using the Homebrew package manager.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then add a global path. Modify and add the following line inside .bash_profile or .zshrc file.

export PATH="/usr/local/bin:/usr/local/sbin:$PATH"

The hit the one by one following command.

brew update
brew install python  # Python 3
sudo pip3 install -U virtualenv

I have already created a Virtual Environment, but you can also create by following steps.

Create a new virtual environment by choosing a Python interpreter and making a ./pythonenv directory to hold it. Type the following command then.

virtualenv --system-site-packages -p python3 ./pythonenv

Go inside that folder.

cd pythonenv

Activate the virtual environment using a shell-specific command.

source bin/activate

If you have installed virtual environment perfectly then virtualenv is active, your shell prompt is prefixed with (pythonenv). See the below image.

 

Install Tensorflow on Mac

Install packages within a virtual environment without affecting the host system setup. Start by upgrading pip. See the following command to upgrade pip.

pip install --upgrade pip

After that, you can see all the packages by typing the following command.

pip list

 

Create a virtual environment

You can see that, I have already installed the TensorFlow package.

Install the TensorFlow pip package

If your system has not tensorflow package then you can install it using the following command.

pip install tensorflow

Basically, package dependencies are already installed, if you have not the newer version of tensorflow then you can upgrade using the following command.

pip install --upgrade tensorflow

So, finally, the Tensorflow is installed on your machine.

Let’s check if it has installed or not.

Create a new folder inside the pythonenv folder called tflow and inside that, create a new file called tflow.py and add the following code inside it.

Related Posts
1 of 3
import tensorflow as tf
import os

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

hello = tf.constant('Kudos, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

In the above code, we have imported the tensorflow as well as the os module.

If you don’t import the os module and use the environ function then it will give us a warning and avoid the warning, we have applied the setting export TF_CPP_MIN_LOG_LEVEL=2.

For more information, you can check out this StackOverflow link.

Finally, run the tflow.py file using the following command and see the output.

python3 tflow.py

 

Install the TensorFlow pip package

If you have seen like this then congratulations!! You have successfully installed Tensorflow on your mac.

Finally, How To Install Tensorflow on Mac Tutorial From Scratch is over.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.