neural-networks.io

neural-networks.io

Install TensorFlow and Keras for Linux

This page presents the installation of Keras for Linux. The following has been done on a fresh Ubuntu install on the following hardware / software versions:

 

# Workspace preparation

Since Python 3 is natively installed with Ubuntu 16.04, no need to install or update Python. However, pip is required for installing TensorFlow and Keras. First, update Ubtuntu to get the lastest kernel and packages versions, then install pip.

# Update Ubuntu and reboot
sudo apt upgrade
sudo apt update

# Reboot

# Install pip
sudo apt install python3-pip
sudo pip3 install --upgrade pip
 

# Virtual environment

Even if it is not mandatory, it is highly recommended to isolate developments from other Python programs. This is the job of virtual environmennts

# Install virtual environment
sudo pip3 install virtualenv

Create a working directory for your virtual environment wherever you want:

# Working directory
mkdir ~/keras
cd ~/keras

Create the virtual environment:

# Create virtual environment
virtualenv venv

Activate the virtualenv environment by issuing the following command:

# Activate virtual environment
source ~/keras/venv/bin/activate
The preceding source command should change your prompt to: (venv)$. You can exit the virtual environment with the deactivate command.
 

# Install TensorFlow and Keras

While the virtual environment is activated, install TensorFlow, then Keras:

# Install TensorFlow
pip install --upgrade tensorflow
# Install Keras
pip install --upgrade keras
 

# Final check

Check your installation:

# Check the Keras backend
python -c "from keras import backend" 
The preceding command should prompt: Using TensorFlow backend.
 

# Optionnal usefull modules

 
# Matlplotlib
# Install Tkinter
sudo apt-get install python3-tk

# Install Matplotlib
pip install --upgrade matplotlib
 
# Visual Studio Code
snap find "visual studio code"
sudo snap install vscode --classic
sudo apt install pylint