Install TensorFlow For Python3
I sat down tonight after having set myself the goal of installing Tensorflow, thinking it might take me a few hours. It's actually its dead easy, so I wanted to post this tutorial to show just how easy it is. The docs list a million-and-one ways to install the tool but this just covers setting up with native Python3 on Ubuntu 16.04.
Run the following commands/script to get tensorflow (CPU only) installed on your Ubuntu 16.04 server.
# Install necessary python packages. sudo apt-get install python3-pip python3-dev -y # Upgrade pipo this is pip3 install --upgrade pip # Install tensorflow (cpu only) pip3 install tensorflow
If you want to use an NVIDIA GPU for tensorflow then run this instead:
# Install necessary python packages. sudo apt-get install python3-pip python3-dev -y # Upgrade pip pip3 install --upgrade pip # Install tensorflow with GPU support pip3 install tensorflow-gpu
Testing Installation Successful
That seemed a little too easy, so let's just write a small script that uses the tensorflow library to test that we have installed it correctly:
#!/usr/bin/python3 import tensorflow as tf hello = tf.constant("Hello, TensorFlow!") sess = tf.Session() print(sess.run(hello))
If you execute it you should get the following output :
Now you have tensorflow installed. I will post more tutorials soon on using Tensorflow, but for now you can read the Python API docs.
If you ever need to uninstall tensorflow just run:
sudo pip3 uninstall tensorflow
First published: 16th August 2018