Now, in preparation for our installation, we will create a new virtual environment in Anaconda. We can do so by using the following instructions:
- We open the Anaconda prompt.
- 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
- 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:
- TensorFlow with CPU support only
- TensorFlow with GPU support
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:
- We type python to start the Python shell.
- We use import tensorflow as tf to import TensorFlow into our Python shell.
- We run hello = tf.constant("Hello"); this will create a constant named hello.
- We create a session using sess = tf.Session().
- 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.