Keras is a neural network library based on the Python programming language designed to simplify machine-learning applications. Keras runs on top of frameworks such as TensorFlow.
Prerequisites
- A Linux machine with access to a command-line/terminal
- A user account with sudo or root privileges
- The Python 3.5 – 3.8 development environment
- The Python3-pip package manager
How to Install Keras on Linux
Keras is built to work with many different machine learning frameworks, such as TensorFlow, Theano, R, PlaidML, and Microsoft Cognitive Toolkit. However, the best framework to use with Keras is TensorFlow.
This blog will cover installing TensorFlow as well.
STEP 1: Install and Update Python3 and Pip
Skip this step if you already have Python3 and Pip on your machine.
If not, open the terminal and enter the following command, depending on your Linux distribution:
CentOS / RedHat:
sudo yum install python3 python3-pip |
Type y when prompted. Let the installation complete the process.
Then, run this command to upgrade Pip:
sudo pip3 install ––upgrade pip |
Ubuntu / Debian:
The process for these distributions is similar:
sudo apt install python3 python3.pip |
sudo pip3 install ––upgrade pip |
Note: If Python 3 or Pip is already available, the system reports that there are no further changes.
STEP 2: Upgrade Setuptools
To upgrade setuptools, enter the following:
pip3 install ––upgrade setuptools |
Without this step, you may receive errors about certain packages requiring a different setuptools version than the one you have on your system.
STEP 3: Install TensorFlow
The TensorFlow installation is straightforward. Use Pip and this command to install it::
pip3 install tensorflow |
Let the download and installation finish.
Verify the installation was successful by checking the software package information:
pip3 show tensorflow |
The system should display the version and other data about TensorFlow.
For a shorter input, use this command:
pip list | grep tensorflow |
STEP 4: Install Keras
Finally, install Keras with the following command:
pip3 install keras |
The terminal shows the confirmation message once the process completes.
Verify the installation by displaying the package information:
pip3 show keras |
STEP 5: Install Keras from Git Clone (Optional)
If you have Git on your system, you can use it to clone a copy of the Keras software package from GitHub.
Note: When Git is not installed, the operating system prompts you to install it before cloning from the Keras GitHub repository. Depending on your system's OS, use one of our guides:
How to Install Git on Ubuntu, How to Install Git on CentOS 7, or How to Install Git on CentOS 8.
To clone the Keras package from GitHub, enter the following:
git clone https://github.com/keras-team/keras.git |
Once the download completes, switch to the /keras directory:
cd keras |
sudo python3 setup.py install |
The output shows the confirmation when the process completes: