TensorFlow installation

Now, in preparation for our installation, we will create a new virtual environment in Anaconda. We can do so by using the following instructions:

  1. We open the Anaconda prompt.
  2. We type the following command line for creating a new virtual environment and pass the name of the environment with anaconda, which will install all of the packages that come with Anaconda:
conda create-n apa anaconda
Here apa stands for advanced predictive analytics. Installation can take some time depending on your internet speed.
  1. Once the installation has been completed, type activate apa to activate the new virtual environment. Here is a screenshot of the Anaconda prompt, showing the installation of Anaconda packages:

Now, the new virtual environment has been activated and we are ready to install TensorFlow inside this new virtual environment.

But before installing TensorFlow, you must know that there are basically following two installations of TensorFlow:

The second option is usually faster because it uses the GPUs in your computer or your devices, but this installation needs Nvidia support. You also need additional software in order to run this installation and it is a little bit more complicated to install.

Here, for easiness, we will install and use the CPU version as there is no difference in writing a program and running it in the CPU or the GPU versions, apart from the speed. We use the following line of code to install TensorFlow in our system:

pip install --ignore-installed --upgrade tensorflow

On running the code, the installation of TensorFlow will be initiated and, once the installation is completed, you will see the following output on your screen:

Now, we will start a Python shell to test the installation by performing the following steps:

  1. We type python to start the Python shell.
  2. We use import tensorflow as tf to import TensorFlow into our Python shell.
  3. We run hello = tf.constant("Hello"); this will create a constant named hello.
  1. We create a session using sess = tf.Session().
If you see similar warning messages to the ones in the following screenshot, you can ignore them, as they are just telling you that you could install with different options so TensorFlow may run faster.
  1. Let's print the result of hello by running the constant within the session using print(sess.run(hello)):

If you get a result of Hello, similar to this screenshot, it means that our installation is correct. So, now we are ready to use TensorFlow to build some models.