How to Install Tensorflow on Ubuntu 18.04 in Google Cloud. TensorFlow is open-source machine learning software developed by Google which is used to train neural networks.
In this tutorial, we’ll install TensorFlow’s “CPU support only” version. This installation is ideal for people looking to install TensorFlow, but who don’t have Nvidia graphics card.
Prerequisites
- A Compute Engine Instance running with atleast 1 GB RAM, see the Setting up Compute Engine Instance.
Setting Up Python 3
Ubuntu 18.04 ships with both Python 3 and Python 2 pre-installed. To make sure all packages are up-to-date, start by updating the system.
SSH to your Compute Engine instance and begin to execute the following commands.
sudo apt update
sudo apt -y upgrade
Once the update and upgrade is complete verify the Python installation using the following command.
python3 -V
Output
Python 3.6.7
Install the Required Packages
sudo apt install python3-pip python3-dev
Once Python is set up, and pip and other tools are installed, we can set up a virtual environment to install Tensorflow.
Setting Up a Virtual Environment
We will be using the virtualenv module here, which is part of the standard Python 3 library.
sudo -H pip3 install virtualenv
mkdir ~/myproject
cd ~/myproject
virtualenv tf-env
Activate the virtual environment by typing.
source tf-env/bin/activate
Your prompt should change to indicate that you are now operating within a Python virtual environment. It will look something like this: (tf-env) username@host:~/myproject$
Install Tensorflow
With your virtual environment activated you can install Tensorflow.
pip install --upgrade tensorflow
Once the installation is completed you can verify the installation using the following command.
python -c 'import tensorflow as tf; print(tf.version)'
Output
1.13.1
Conclusion
Now you have learned how to install Tensorflow on Ubuntu 18.04 on Google Cloud Platform.
Thanks for your time. If you face any problem or any feedback, please leave a comment below.
Hello,
Good tutorial.
Tell me : why do you use Virtual Environment. Does it success in non virtual environment ?(Because I try on VM Compute Engine : default environment = KO, in virtual OK)