How to setup TensorFlow on your Machine

In this set of tutorials, we explain how to setup your machine to run TensorFlow codes "step by step".

What is TensorFlow?

TensorFlow is a machine learning / deep learning library developed by Google. The following video from the developer answers this question.

Why TensorFlow?

Deep learning has found it's way to different branches of science. Well, let's see some applications of TensorFlow...

Similar to many other libraries, we tried installing many side packages and libraries and experienced lots of problems and errors. We finally came up with a general solution and recommend installing the following libraries and packages as the best way around it.

0. CUDA-toolkit & cuDNN library (for GPU version of TensorFlow only)

TensorFlow comes with two versions.

  1. CPU version: Is easy to install but it is slow.
  2. GPU version: Is tricky to install but it is fast.

To use the GPU version, you should make sure your machine has a cuda enabled GPU and both CUDA-tooklit and cuDNN are installed on your machine properly.

Follow this instruction to install the CUDA-toolkit and cuDNN library.


1.1. Python programing language

TensorFlow has several APIs (Application Program Interface). But python API is the most complete and easiest to use [1]. Python comes pre-installed with most Linux and Mac distributions. However, here we will install the python via Anaconda distribution because it gives the flexibility to create multiple environments for different versions of python and libraries. TensorFlow used to run only with python 3.5 on windows. But recently they added the support for both 3.5 and 3.6. We will use Python 3.5 for all operating systems (Windows, Linux, and Mac) to keep it uniform among OSs throughout the tutorial. But feel free to use your own preferred python version.

If you are interested to learn more about python basics, we suggest you these tutorials:


-corey schafer

1.2. Package manager

To run TensorFlow, you need to install the library. Libraries are also called packages. So, you need to have a  package management system. There are 2 famous package management system:

    a) Pip: is the default package management system that comes with python. Pip installs python packages only and builds from the source. So, if you want to install a package, you have to make sure you have all the dependencies. For example, if you want to install tflearn package, you have to make sure you have already installed tensorflow. Otherwise, you will get errors running tflearn

   b) Conda: is the package manager from Anaconda distribution. conda can be used for any software. Conda installs binaries meaning that it skips the compilation of the source code. If you don't want to deal with dependencies, it is better to install your package with conda. For example, if you want to install tflearn package, you do not need to worry about installing tensorflow package. It will automatically install all the needed packages. But, if you have a GPU in your systam and the binary file is build based on CPU version of the tensorflow you will not be able to use the GPU version. Otherwise, you have to find the proper binary which has been built on GPU version.

Follow this instruction to install python and conda.

2. TensorFlow library

Now, having installed all the prerequisites, you can start installing the TensorFlow library.

Follow this instruction to install TensorFlow.

3. Integrated Development Environment (IDE)

Now that the TensorFlow is installed on your machine. You can start coding. You can write your codes in any editor (terminal, emacs, notepad, ...). We suggest using PyCharm because it offers a powerful debugging tool which is very useful especially when you write codes in TensorFlow.

Follow this instruction to install PyCharm.

4. Run a sample code

Write a short program like the following and run it to check everything is working fine:

In [ ]:
import tensorflow as tf
a = tf.constant(2)
with tf.Session() as sess:

Final note We suggest you to install some useful packages throughout these tutorials. In your terminal, activate the tensorflow environment and install the following packages:

(for Windows):

activate tensorflow
pip install matplotlib jupyter 

References: [1]: 

Thanks for reading! If you have any question or doubt, feel free to leave a comment. To download jupyter notebooks and fork in github please visit our github.


© 2018 Easy-TensorFlow team. All Rights Reserved.