TensorFlow is an open source platform for machine learning built by Google. TensorFlow is used by a number of organizations including Twitter, PayPal, Intel, Lenovo, and Airbus.
TensorFlow can be installed system-wide, in a Python virtual environment, as a Docker container or with Anaconda .
TensorFlow supports Python 2 and 3. We will use Python 3 and install TensorFlow in a virtual environment .
Virtual environment allows you to have several different isolated Python environments on one computer and install specific versions of modules based on each project, without worrying that it will affect your other Projects.
Install TensorFlow on Rocky Linux 8 and CentOS 8
Unlike other Linux distributions, Python is not installed by default on Rocky Linux 8 . To install Python 3 on CentOS 8, run the following command as root user or
sudo in your terminal:
sudo dnf install python3
The above command will install Python 3.6 and pip . To run Python 3, you must type
python3explicitly, and to run pip type
Starting from Python 3.6, the recommended way to create a virtual environment is to use modules
Go to the directory where you want to save the TensorFlow project. This can be in your home directory or another directory where you can have read and write access.
Create a directory new for the TensorFlow project and go into it:
Inside the directory, run the following command to create a virtual environment :
python3 -m venv venv
The above command creates a directory named
venv, contains a copy of the Python binary, the pip Python library, and other supporting files. You can use any name you want for the virtual environment.
To start using a virtual environment , activate it by typing:
Once activated, the directory
bin in the virtual environment will be added at the beginning of the variable
$PATH. Additionally, your shell prompt will change, and it will display the name of the virtual environment you are currently using. In this case it is
Install AndroidX86 on VirtualBox and Desktop PC
Tensorflow and pip on Rocky Linux 8 and CentOS 8
TensorFlow installation requires
pipversion 19 or higher. Run the following command to upgrade
pipto the latest version:
pip install --upgrade pip
Once the virtual environment is created and activated, install the TensorFlow library using the following command:
pip install --upgrade tensorflow
If you have a dedicated NVIDIA GPU and want to harness the power of that GPU for processing, install the package
tensorflow-gpu, which includes and extends tensorflow functionality for GPU support.
In a virtual environment , you can use pip commands instead of pip3 and python instead of python3.
To verify the installation, run the following command, which will print the TensorFlow version:
python -c 'import tensorflow as tf; print(tf.__version__)'
At the time of writing this article, the latest stable version of TensorFlow is
Your version of TensorFlow may differ from the version shown here.
If you’re new to TensorFlow, visit the Getting Started page with TensorFlow and learn how to build your first Machine Learning app. You can also clone TensorFlow Models or the TensorFlow-Examples repository from Github and explore and test TensorFlow examples.
When you are done with your work, deactivate the environment by typing
deactivate, and you’ll be back in your normal shell.
At this point you have successfully installed TensorFlow, and you can start using it.
We’ve shown you how to install TensorFlow inside a virtual environment on Rocky Linux 8 and CentOS 8.
Leave a Reply