Installing TensorFlow is not a tedious task if you have a fast internet connection. The main tool we need to have is pip, which is a package management tool used for managing and installing software packages in Python.
Let's begin installing TensorFlow through the following steps:
- Here is the command to install pip on Ubuntu:
$ sudo apt-get install python-pip python-dev
- After installing pip, you can install TensorFlow using the following command:
$ pip install tensorflow
This would install the latest and stable TensorFlow library.
If you would like a GPU version, then use this:
$ pip install tensorflow-gpu
- You have to execute the following command to set a bash variable called TF_BINARY_URL. This is for installing the correct binaries for our configuration. The following variable is for the Ubuntu 64 bit, Python 2.7, CPU-only version:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
If you have an NVIDIA GPU, you may need a different binary. You may also need to install CUDA toolkit 8.0 cuDNN v5 for installing this, as shown here:
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
- After defining the bash variable, use the following command to install the binaries for Python 2:
$ sudo pip install --upgrade $TF_BINARY_URL
If everything works fine, you will get the following kind of output in the Terminal:
If everything has been properly installed on your system, you can check it using a simple test. Open a Python Terminal, execute the following lines, and check whether you are getting the results shown in the following screenshot:
We will look at an explanation of the code in the next section.
Here is our hello world code in TensorFlow:
import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print (sess.run(hello)) a = tf.constant(12) b = tf.constant(34) print(sess.run(a+b))
The output of the preceding code is as shown in the preceding screenshot. In the next section, we will look at a few important concepts of TensorFlow.