How to Install TensorFlow on CentOS 7

Install TensorFlow on CentOS 7

In this article, we will have explained the necessary steps to install and configure TensorFlow on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

TensorFlow™ is an open-source Machine Learning framework released by Google. From its official site, TensorFlow™ is an open-source software library for high-performance numerical computation, which allows easy deployment of computation across a variety of platforms (CPUs, GPUs, TPUs), and from desktops to clusters of servers to mobile and edge device.

Install TensorFlow on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo yum update

Step 2. Install Python.

Let’s started with the installation of Python:

sudo yum -y install https://centos7.iuscommunity.org/ius-release.rpm
sudo yum -y install python36u
sudo yum -y install python36u-pip
sudo yum -y install python36u-devel

Step 3. Create Virtual Environment.

Create a Python Virtual Environment called tensorflow_env using the Python module venv. And each Python Virtual Environment has its own Python binary:

mkdir tensorflow_env
cd tensorflow_env
python3.6 -m venv my_tensorflow

To start using this virtual environment, you need to activate it by running the activate script:

source my_tensorflow/bin/activate

Once your virtual environment is activated, you should see something similar to the below:

[[email protected] tensorflow_env]# source my_tensorflow/bin/activate
(my_tensorflow) [[email protected] tensorflow_env]#

Step 4. Install TensorFlow.

Now that the virtual environment is activated, it’s time to install the TensorFlow library:

pip3 install --upgrade tensorflow

Step 5. Creating Simple TensorFlow Program.

Once the installation is completed, you can check if your TensorFlow is in running condition or not:

sudo nano testTensorFlow.py
#!/bin/python3
import tensorflow as tf
hello = tf.constant("Hello, world!")
session = tf.Session()
print(session.run(hello))

Save and close the file, then executing this python file with the following command:

python3 testTensorFlow.py

Outputs:

(my_tensorflow) [[email protected] tensorflow_env]# python testTensorFlow.py
WARNING: Logging before flag parsing goes to stderr.
W0624 22:22:46.206940 140070126434112 deprecation_wrapper.py:112] From testTensorFlow.py:4: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2019-08-24 22:22:46.207794: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-08-24 22:22:46.214758: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1800000000 Hz
2019-08-24 22:22:46.214794: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4470f70 executing computations on platform Host. Devices:
2019-08-24 22:22:46.214711: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): , 
b'Hello, world!'

Congratulation, you have learned how to install and configure TensorFlow on CentOS 7. If you have any questions, please leave a comment below.