TensorFlow is an open-source library used to solve machine-learning problems and built by Google Inc. It can run on GPU or CPU-based multiple environments and is used by different companies in which PayPal, Twitter, Lenovo, and Airbus are included. You can install TensorFlow on different platforms such as in a python virtual environment, Anaconda, or Docker container. This article will elaborate on the installation of TensorFlow on the CentOS 8 system. TensorFlow supports both python versions python2 and python3. However, in this article, we will use python3 and install TensorFlow inside the python virtual environment. The main advantage of using the virtual environment is that it allows multiple various python isolated environments on a single system and installs a specific module on a per-project basis without affecting the other projects.
Installation of TensorFlow on CentOS 8
As we know, that TensorFlow is a Python-based library. So, python is required to use this library on your system.
Install Python
TensorFlow is not installed on the CentOS system by default. For this purpose, install python by running the below-given command on the terminal with sudo privileges:
$ sudo dnf install python3
We have already installed python on this system. So, by using the below-mentioned command display the installed version:
$ python3 –V
From the above image, you can see the python 3.6.8 version is installed on this system.
Create Python virtual environment
The recommended method is to create a python virtual environment is to use a ‘venv’ module. So, create a separate directory where you have read or write permissions to store the TensorFlow projects. Use the following command and create a new ‘tensorflow_project’ directory:
$ mkdir tensorflow_project
After that, navigate into it by running the below-mentioned command:
$ cd tensorflow_project
Now, create a virtual environment inside a ‘tensorflow_project’ directory using the below-given command:
$ python3 -m venv venv
The above-given command will create a directory with the name ‘venv’ that contains all python binaries, standard pip python library, and other supporting files. You can choose any name for your virtual environment that you want to assign.
Activate virtual environment by executing the below-mentioned command:
$ source venv/bin/activate
Once the virtual environment is activated, the terminal’s prompt will be changed and the name of the python virtual environment will display at the beginning of the shell.
Install Python pip-tools
The installation requirement of the TensorFlow is pip version 19 or the latest. So, using the following command upgrade the pip tool to install the latest pip version:
(venv) $ pip install --upgrade pip
Install TensorFlow
Now, install the TensorFlow library by running the below-given command:
(venv) $ pip install --upgrade tensorflow
Inside the python virtual environment, you do not need to use pip3 just use pip and use python instead of python3.
Verify TensorFlow installation
It is time to verify the TensorFlow installation, type the below-mentioned command on the terminal and the installed version will show on the terminal screen:
(venv) $ python -c 'import tensorflow as tensorfl; print(tensorfl.__version__)'
You can now use the TensorFlow library on your CentOS 8 system and run various deep learning and TensorFlow models.
Deactivate virtual environment
Once you have finished your project, you can also deactivate the virtual environment by executing the below-given command on the terminal window:
(venv) $ deactivate
You will back to the normal shell after running the above command as follows:
Conclusion
We have performed the installation procedure of TensorFlow on CentOS 8 system in this article. We have described how to create a new python virtual environment and install TensorFlow, pip-tools inside the environment. I hope this tutorial will help you in the installation of the TensorFlow library on your CentOS 8 system. Thanks!