In this set of tutorials, we explain how to setup your machine to run TensorFlow codes "step by step". For each step, we would need to know what specific version of the software we would need for the TensorFlow version we are going to install. We can check the list of the tested build configurations for each TensorFlow version from [https://www.tensorflow.org/install/source#gpu].
For example, for tensorflow-2.10.0 we need:
- python 3.7 to python3.10
- CUDA toolkit 11.2
- cuDNN 8.1
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 Miniconda distribution because it gives the flexibility to create multiple environments for different versions of python and libraries.
To run TensorFlow, you need to install the package. packages are also called libraries. So, you need to have a package management system. There are 2 famous package management systems:
-
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 codes.
-
Conda: is the package manager from Miniconda and Anaconda distributions. 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.
TensorFlow comes with two versions.
-
CPU version: Is easy to install but it is slow.
-
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.
Now, having installed all the prerequisites, you can start installing the TensorFlow library.
Follow this instruction to install TensorFlow.
Now that the TensorFlow is installed in 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.
Write a short program like the following and run it to check everything is working fine:
import tensorflow as tf
a = tf.constant("Hello from TensorFlow")
tf.print(a)It must print out Hello from TensorFlow.
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(for Linux & Mac):
source activate tensorflow
pip install matplotlib jupyter[1]: https://www.tensorflow.org/api_docs/ ↩
Thanks for reading! If you have any question or doubt, feel free to leave a comment in our website.