How To Install TensorFlow on Centos 7

In this article, we want to teach you How To Install TensorFlow on Centos 7.

TensorFlow is an open-source end-to-end platform for creating Machine Learning applications.

TensorFlow allows developers to create machine learning applications using different tools, libraries, and community resources.

How To Install TensorFlow on Centos 7

In this article, you learn to use Python 3 and install TensorFlow inside a virtual environment on Centos 7.

You need to log in to your server as a non-root user with sudo privileges. To do this, you can check the Initial Server Setup article for Centos 7.

Install Python 3 on Centos 7

You need to install Python 3 from the Software Collections (SCL) repositories.

Centos 7 comes with Python 2.7.5. SCL will allow you to install newer versions of python 3.x.

First of all, you need to install the SCL release file with the following command:

sudo yum install centos-release-scl

Now you can install Python 3.6 on Centos 7 with the following command:

sudo yum install rh-python36

Here you need to create a virtual environment on Centos 7 for the TensorFlow project.

Create a Virtual environment on Centos 7

You can use the venv module to create a virtual environment.

First, you need to launch a new shell to access Python 3.6:

scl enable rh-python36 bash

Now navigate to a directory where you want to store your TensorFlow project.

It can be your home directory or any other directory where the user has read and write permissions.

Then, create a new directory for the TensorFlow project with the following command:

mkdir tensorflow_project

switch to the directory:

cd tensorflow_project

From the directory, run the following command to create the virtual environment:

python3 -m venv venv

We named the directory venv. You can choose another name for it.

Activate the venv environment with the following script:

source venv/bin/activate

Your prompt shell will change to:

(venv) $

Install TensorFlow

To install TensorFlow you need pip version 19 or higher. Run the following command to upgrade it to the latest version:

Now you can install Tensorflow with the following command:

(venv) $ pip install --upgrade tensorflow

Note: If you have a dedicated NVIDIA GPU and want to take advantage of its processing power, instead of tensorflow install the tensorflow-gpu package which includes GPU support.

Note: Within the virtual environment, you can use the command pip instead of pip3 and python instead of python3.

You can verify your installation of TensorFlow on Centos 7 with the following command:

(venv) $ python -c 'import tensorflow as tf; print(tf.__version__)'

In your output you will see:


Your TensorFlow version may differ from the version shown here.

When you are done, you can deactivate the virtual environment with the following command and go back to your normal shell:

(venv) $ deactivate


At this point, you learn to Install TensorFlow on Centos 7 with the virtual environment.

Hope you enjoy it.

For more articles, you can visit the orcacore website.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!