TensorFlow is an open source platform for machine learning developed by Google. It can run on the CPU or GPU of different devices, and it is used by many organizations, including Twitter, PayPal, Intel, Lenovo, and Airbus.
TensorFlow can be installed as a system-wide installation, in a Python virtual environment, as a Docker container, or installed with Anaconda.
This article explains how to install TensorFlow on CentOS 8.
TensorFlow supports both Python 2 and 3. We will use Python 3 and install TensorFlow in a virtual environment. A virtual environment allows you to have multiple different and isolated Python environments on a computer, and rush each project to install the specified version of the module without worrying about it affecting other projects.
Unlike other Linux distributions, Python is not installed on the default CentOS 8. To install Python3 on CentOS 8, run the following command as root or sudo user in the terminal:
sudo dnf install python3
The above command will install Python 3.6 and pip. To run Python 3, you need to enter python3 and pip3 to run pip.
Starting from Python 3.6, the recommended way to create a virtual environment is to use the venv
module.
Switch to a directory, which is where you store your TensorFlow project. It can be your home directory or any other directory where the user has read and write permissions.
Create a new directory for the TensorFlow project and switch to the directory:
mkdir tensorflow_project
cd tensorflow_project
In this directory, run the following command to create a virtual environment:
python3 -m venv venv
The above command creates a directory named venv
, which contains Python binary files, pip standard Python library, and other supporting files. You can name the folder with any name you want.
To start using a virtual environment, enter the following command to activate it:
source venv/bin/activate
Once activated, the bin directory of the virtual environment will be added to the front of the $PATH environment debate. Of course, your shell prompt will change and it will display the name of the virtual environment you are using. In this example, venv
is displayed.
TensorFlow installation requires pip
version 19 or higher. Run the following command to upgrade pip
to the latest version:
pip install --upgrade pip
Now that the virtual environment has been created and activated, use the following command to install the TensorFlow library:
pip install --upgrade tensorflow
If you have a separate NVIDIA GPU and you need to use its processing power, do not use the
tensorflow
package, but install thetensorflow-gpu
package, which includes GPU support.
In this virtual environment, you can use the commandpip
to replacepip3
, andpython
to replacepython3
To verify the installation, run the following command, which will print the version number of TensorFlow:
python -c 'import tensorflow as tf; print(tf.__version__)'
As of this writing, the latest stable version of TensorFlow is 2.1.0:
2.1.0
Your TensorFlow version may be different from the one shown.
If you are a TensorFlow novice, browse the Get Started with TensorFlow page and learn how to build your first ML application. You can also clone TensorFlow Models or TensorFlow-Examples from Github and browse and test TensorFlow examples.
Once you have finished your work, deactivate the environment, type deactivate
, and you will return to the normal shell.
deactivate
that's it! You have successfully installed TensorFlow and you can start using it.
We have shown you how to install TensorFlow in a virtual environment on CentOS 8.
Recommended Posts