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. TensorFlow supports both python versions python2 and python3.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux System CPU optimization queries.
In this context, we shall look into the installation procedure of TensorFlow on the CentOS 8 system.
You can install TensorFlow on different platforms such as in a python virtual environment, Anaconda, or Docker container. Here, 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.
To start with this Installation Procedure, follow the steps outlined below.
1. Install Python
Basically, TensorFlow is a Python-based library. So, python is required to use this library on your system.
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
Now, to see the version of python3 installed on this system, run the command:\
$ python3 –V
2. 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
This 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.
Next, 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.
3. 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
4. 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.
5. Confirm TensorFlow installation
To verify 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.
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
This will take you back to the normal shell.
This article covers the installation procedure of TensorFlow on CentOS 8 system. TensorFlow is a machine learning platform by Google. It is basically an open source and has a huge number of tools, libraries and other resources developed by both its developer community as well as Google and other corporations.
TensorFlow is available for all the popularly used operating systems, viz. Windows, Mac OS, GNU/Linux. It can be downloaded and installed from either Python Package Index using the pip tool and can be run in a virtual python environment. Another way to use it is to install it as a Docker container.