TensorFlow is a free, open-source machine learning and deep learning framework that can work on almost all operating systems. Due to its multi-purpose utilities and ease of compatibility, developers prefer to use this framework for developing and training ML algorithms. This tutorial will give you a quick walkthrough of installing TensorFlow in Windows, Linux, and Mac operating systems.



TensorFlow Installation Types

When installing TensorFlow, there are two options: either choose only the CPU or GPU-supported version. Install the CPU version to design and train simple machine learning models and install the GPU-supported versions for complex graphical tasks such as image processing.

The GPU-supported TensorFlow is compatible with NVIDIA GPU cards with CUDA Compute 3.5 or higher; it requires some libraries and drivers.

  1. NVIDIA GPU drivers
  2. CUDA Toolkit (CUDA 9.0)
  3. NCCL 2.2 (optional)
  4. cuDNN SDK (7.2 or higher)
  5. TensorRT (To improve latency and throughput).

Installation Method

The first thing you need in your system is a Python interpreter. You can go with 3.4 or above, as it is the best version to start working with TensorFlow. To install TensorFlow, you also need a pip package manager for Python. Usually, pip comes as a built-in tool, and it gets installed together with Python.

To check the version of pip installed on your system, type: pip3 --version in the command prompt (in administrative mode).

TensorFlow Installation Process on Windows

Setting up TensorFlow Using PIP

The following command installs TensorFlow via the pip package manager:

pip3 install --upgrade tensorflow

The command may take some time to execute and install TensorFlow. The following command installs GPU-supported TensorFlow:

pip3 install tensorflow-gpu

Setting up TensorFlow Using Anaconda

Anaconda does not come with Python as a built-in tool. You have to download it from its official site and install the package manually. After installation, you can search for "Anaconda Prompt" on the Windows Start Menu.

If you want to see the details of the conda package, at the prompt, you must type the following command:

$ conda info

It's good practice to create a different work environment for each project so you can work with a specific version of varying Python libraries without affecting other Python projects.

To create a virtual environment for TensorFlow, execute the following conda command:

conda create -n [environment-name]

The following command activates the environment:

activate [environment-name]

The following command installs TensorFlow via Anaconda:

$ conda install tensorflow

TensorFlow Installation Process on Linux

The TensorFlow installation process is straightforward in Linux; You need to execute the following commands below.

First, a virtual environment needs to be created for the Python venv model using the following command:

sudo apt install python3-venv python3-dev

Next, to create and activate a Python 3 virtual environment:

mkdir tensor
cd tensor/
python3 -m venv [environment-name]
source [environment-name]/bin/activate

Now check your pip version using the following command:

pip --version

Check for the latest pip version and if it does not match, use the following command to upgrade your pip to the latest version:

pip install --upgrade pip

Now, install TensorFlow using the following command:

pip install --upgrade tensorflow

Now execute these two lines of code (saving as .py files) to check whether TensorFlow got installed or not.

import tensorflow as tf
print(tf.__version__);

TensorFlow Installation Process on Mac

First, you'll need to download and install Python on your Mac OS if it's not already installed.

Verify the Python version by executing the following command in the terminal:

python3 --version

Now, check whether the brew is installed on your system:

brew --version

Now, Create a virtual environment with the following command:

brew install virtualenv

Now create a directory to hold the environment:

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

Go inside the ./pythonenv directory.

cd ./pythonenv

Activate the virtual environment:

source bin/activate

Once you go inside the directory and activate the virtual environment, it is time to install the TensorFlow.

brew install tensorflow

It might take some time. Once it gets installed completely, you are good to go and use TensorFlow in your Python program.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram