TensorFlow is Google’s open-source platform for machine learning designed to simplify the process of implementing machine-learning models.
Researchers, data scientists, and developers use this end-to-end library for numerical computation. TensorFlow runs on multiple CPUs, GPU, as well as mobile operating systems.
In this tutorial, learn how to install TensorFlow on CentOS 7.
Prerequisites
- A CentOS Linux system
- Access to a command line/terminal window (Ctrl+Alt+F2)
- A user account with sudo privileges
- Access to the root user
- Pip 19.0 or later
Step 1: Enable and Update EPEL Repository
sudo yum -y install epel-release
yum -y update
Step 2: Install Required Packages
If you do not have Python installed on CentOS, run the following command to install pip (a package management system for Python) and the language itself:
sudo yum -y install gcc gcc-c++ python-pip python-devel atlas atlas-devel gcc-gfortran openssl-devel libffi-devel
The output shows that the system downloaded dependencies.
Step 3: Create a Virtual Environment
Using the pip
command, install and upgrade a virtual environment software. We recommend using Virtualenv, a tool specifically designed for creating isolated Python environments.
Use the following command to install and upgrade Virtualenv on CentOS:
pip install --upgrade virtualenv
Create a new environment by typing:
virtualenv --system-site-packages ~/venvs/tensorflow
Finally, activate the environment:
source ~/venvs/tensorflow/bin/activate
Activating the environment changes the command line prompt, adding the virtual environment’s bin directory as a prefix. This means you are now working inside the virtual environment.
Step 4: Install TensorFlow
Install TensorFlow for CPU
pip install --upgrade tensorflow
Install TensorFlow for GPU
pip install --upgrade tensorflow-gpu
Note, TensorFlow with GPU support needs additional hardware and software. To learn more, refer to TensorFlow’s documentation on GPU support.
Install Older Versions of TensorFlow
pip install tensorflow==package_version
For example, to install TensorFlow for CPU version 1.14, type:
pip install tensorflow==1.14
To install TensorFlow for GPU version 1.14, type the command in the following format:
pip install tensorflow-gpu==1.14
TensorFlow 1.15 supports both CPU and GPU workloads in a single package. To install the 1.15 release, run the following command:
pip install tensorflow-gpu==1.15rc2
Step 5: Verify TensorFlow Installation
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
Conclusion