How to install Tensorflow in MacOs

How to install Tensorflow in MacOs

  • Install Anaconda
  • Create a .yml file to install Tensorflow and dependencies
  • Launch Jupyter Notebook

Step 1: Install Anaconda

Download anaconda from here Install Anaconda

Create .yml file to install Tensorflow and dependencies

It includes

  • Locate the path of Anaconda
  • Set the working directory to Anaconda
  • Create the yml file (For MacOS user, TensorFlow is installed here)
  • Edit the yml file
  • Compile the yml file
  • Activate Anaconda
  • Install TensorFlow (Windows user only)

Step 1) Locate Anaconda (use the Terminal)

Command: which anaconda

We have to create a new folder inside Anaconda folder that folder contains Ipython, Jupyter and TensorFlow. This is faster way to install libraries and softwares is to write a yml file.

Step 2) Set working directory

You have to set a working directory where yml file will be placed.

Open you terminal and type:

Command: cd anaconda3

Step 3) Create the yml file

Now you have to create yml file copy and paste below code to your terminal

Command: touch hello-tf.yml

A new file will be create which named hello-tf.yml inside anaconda3 folder

Step 4: Edit yml file

You are ready now to edit your yml file by copy below code to your teminal

Command: vi hello-tf.yml

Now from commands appear on screen you enter an edit mode. Inside this mode, you can, after pressing esc:

Press i to edit

Press w to save

Press q! to quit

Write below code in the edit mode and press esc followed by :w

Code:

name: hello-tfdependencies:  

  - python=3.6  

  - jupyter  

  - ipython  

  - pandas  

  - pip:      

  - https://storage.googleapis.com/tensorflow/MacOS/cpu/tensorflow-1.5.0-py3-none-any.whl

Press esc followed by :q! to quite the edit mode.

Step 5) Compile the yml file

To compile the .yml file use below code which will develop conda environment:

Command: conda env create -f hello-tf.yml

It takes times. It will take around 1.1gb of space in your hard disk.

Step 6) Activate conda environment

Command: conda env list

You need to switch to hello-tf to activate the environment

Command: source activate hello-tf

Now You can check all dependencies are in the same environment.

Commands: 

which python

which jupyter

which ipython

Optional: You can check for update/install tensorflow.

Command: pip install --upgrade tensorflow

Last Process:

  • You will proceed as follow:
  • Activate hello-tf conda environment
  • Open Jupyter
  • Import tensorflow
  • Delete Notebook
  • Close Jupyter

Step 1) Activate conda

Command: conda activate hello-tf

Step 2) Open Jupyter

Command: jupyter notebook

Step 3) Import Tensorflow

To import tensorflow below step is followed

import tensorflow as tf

Let's write your first code with TensorFlow.

hello = tf.constant('Hello, gooposts!')

hello

Congratulation. You successfully install TensorFlow with Jupyter on your Machine.

You have to open a new session with for each transection of jupyter and new opening

Command: source activate hello-tf

 

Enjoyed this article? Stay informed by joining our newsletter!

Comments

You must be logged in to post a comment.

Related Articles
About Author
Recent Articles