TensorFlow is a very popular open source software library created by Google Inc. for machine learning. It is used to implement machine learning and deep neural network training methods, as well as to visualize graphs and data flow diagrams of complex mathematical equations.
In this post, we will demonstrate a step-by-step guide to installing TensorFlow on CentOS 8 in a Python-focused virtual environment.
TensorFlow can be installed on CentOS 8 in a Python-centric virtual environment; CentOS 8 has built-in Python3 installed, which you will need for the next steps.
Step 1. Check Python version on CentOS 8.
Let’s check the python3 version:
$ python3 --version
If it is installed, the next step is to create a Python-centric virtual environment. Otherwise, if Python 3 is not installed on your machine, you can install Python 3 using the command below:
$ sudo dnf install python3
After installing Python 3, you can run python3 and pip3 commands on your CentOS 8 system.
Step 2: create a virtual environment
To create a Python oriented virtual environment, go to the directory where you want to create it. It is also a good idea to create a Python-specific virtual environment in your home directory or wherever you have read and write permissions. After navigating to the directory where you want to create the virtual environment, create a new directory to create the TensorFlow project in it.
$ mkdir tensorflow_dir
Now change to the newly created “tensorflow_dir” directory.
$ cd tensorflow_dir
In the tensorflow_dir directory, enter the following command to create a virtual environment:
$ python3 -m venv venv
In the above command, we created a “venv” directory and a Python-specific virtual environment named “venv”. If you want to name the virtual environment of your choice, replace the second “venv” with the desired virtual environment name.
Step 3. Start the virtual environment
To start the virtual environment, enter the command below:
$ source venv/bin/activate
After starting the virtual environment, you can see the bin directory of the environment at the beginning of the $ PATH variable.
We have successfully created a Python-centric virtual environment for TensorFlow. Let’s install TensorFlow now.
Step 4: Install TensorFlow with pip
Before running the installer, update your pip version using the command below:
$ pip3 install --upgrade pip
After updating the package, run the installer using the command below:
$ pip3 install --upgrade tensorflow
It is now installed and you can verify that TensorFlow version 2.4.1 is successfully installed on CentOS 8.
After using TensorFlow, enter the following command to deactivate the Python-centric virtual environment:
In this post, you learned how to create a Python-focused virtual environment and install TensorFlow on CentOS 8. We hope you found this post helpful when installing TensorFlow on CentOS 8. If you are new to TensorFlow or would like to learn more about TensorFlow, read TensorFlow Getting Started Guide on their official website.