Easy Steps To Install TensorFlow on Rocky Linux 8 – OrcaCore

Posted on

Easy Steps To Install TensorFlow on Rocky Linux 8 - OrcaCore

Easy Steps To Install TensorFlow on Rocky Linux 8 – OrcaCore

This guide aims to walk you through the process to Install TensorFlow on Rocky Linux 8. TensorFlow is a powerful open-source library used extensively for numerical computation, large-scale machine learning, deep learning, and other demanding statistical and predictive analytics tasks. This technology significantly simplifies and accelerates the development of machine learning models, streamlining the acquisition of data, the deployment of predictions at scale, and the refinement of future results.

Follow these steps on the Orcacore website to begin your Install TensorFlow on Rocky Linux 8!

TensorFlow offers flexibility in its installation, allowing you to choose from system-wide installation, a Python virtual environment, a Docker container, or even using Anaconda.

Before starting, ensure you are logged into your Rocky Linux 8 server as a non-root user with sudo privileges. If you haven’t already, refer to our guide on Initial Server Setup with Rocky Linux 8 to create such a user.

In this article, we will focus on installing TensorFlow within a Python virtual environment.

TensorFlow Python Setup on Rocky Linux 8

To begin, you will need Python installed on your Rocky Linux 8 system. Start by updating your local package index using the following command:

sudo dnf update -y

Install Python 3

Next, install Python 3 on your server with the following command:

sudo dnf install python3 -y

This command installs Python 3.6 along with pip, the Python package installer. To execute Python 3, use the python3 command, and for pip, use pip3.

Now, navigate to the directory where you intend to store your TensorFlow project. This could be your home directory or any other directory where the user possesses read and write permissions.

Create a new directory for your TensorFlow project and navigate into it using the following commands:

# mkdir tensorflow_project
# cd tensorflow_project

Create Virtual Environment

Now, use the venv module to create a new virtual environment for TensorFlow:

python3 -m venv venv

This command generates a new directory named "venv." Feel free to choose a different name for your virtual environment if desired.

Activate Virtual Environment

To utilize the virtual environment, activate it with the following command:

source venv/bin/activate

You will notice that your shell’s prompt changes to indicate the active virtual environment, usually displaying the name of the environment in parentheses.

For TensorFlow installation, pip version 19 or higher is required.

Upgrade pip to the latest version using the following command:

(venv) $ pip install --upgrade pip

Install TensorFlow

Install TensorFlow using the following command:

(venv) $ pip install --upgrade tensorflow

Note: If your system has a dedicated NVIDIA GPU and you wish to leverage its processing power, install the tensorflow-gpu package instead of tensorflow. This package includes GPU support.

Note: Within the virtual environment, you can use the command pip instead of pip3 and python instead of python3.

Once the installation is complete, verify it by checking the TensorFlow version:

(venv) $ python -c 'import tensorflow as tf; print(tf.__version__)'
2.10.0

Your TensorFlow version may differ from the version shown above.

When you have completed your work, deactivate the virtual environment with the following command:

(venv) $ deactivate

That’s it; you’re done! You have successfully installed TensorFlow on Rocky Linux 8.

Conclusion

At this point, you’ve successfully learned how to Install TensorFlow on Rocky Linux 8. Following the steps outlined above ensures a smooth installation, enabling you to harness TensorFlow’s potent machine learning capabilities on your Rocky Linux 8 system.

We hope you found this guide helpful. Please follow us on Facebook, Twitter, and YouTube for more tutorials and updates.

Also, you might find these articles useful:

Install VS Code on Rocky Linux 8

Install Webmin on RHEL 8

Install gitlab-ce Rocky Linux 8

Set up PHP 7.4 For Rocky Linux 8

Install DotNet Core Rocky Linux 8

Anaconda Python Rocky Linux 8

AnyDesk Remote Desktop Rocky Linux 8

Squid Proxy Server Rocky Linux 8

Install LibreNMS Rocky Linux 8

Alternative Installation Methods

While the virtual environment approach is excellent for isolating dependencies and managing projects, here are two alternative ways to install TensorFlow on Rocky Linux 8: using Conda and using Docker.

1. Installing TensorFlow using Conda

Anaconda is a popular Python distribution, especially in the data science and machine learning community. It simplifies package management and environment creation.

Explanation:

Conda manages packages and environments similarly to venv, but it also handles non-Python dependencies, making it suitable for complex projects. Using Conda, you can create an environment with a specific Python version and TensorFlow.

Steps:

  1. Install Anaconda or Miniconda: If you don’t have it already, download and install Miniconda (a minimal version of Anaconda) from the official website or using the following command:

    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    bash Miniconda3-latest-Linux-x86_64.sh

    Follow the on-screen instructions. Make sure to initialize Conda in your .bashrc or .zshrc file.

  2. Create a Conda Environment: Create a new environment for TensorFlow:

    conda create -n tensorflow_env python=3.8

    This command creates an environment named tensorflow_env with Python 3.8. You can adjust the Python version as needed.

  3. Activate the Environment: Activate the newly created environment:

    conda activate tensorflow_env
  4. Install TensorFlow: Install TensorFlow using Conda:

    conda install -c conda-forge tensorflow

    The -c conda-forge specifies the channel from which to install TensorFlow. Conda-forge is a community-led collection of packages that often provides more up-to-date versions. To Install TensorFlow on Rocky Linux 8 using GPU, you will need to install the tensorflow-gpu package instead.

  5. Verify the Installation: Verify the installation by checking the TensorFlow version:

    python -c 'import tensorflow as tf; print(tf.__version__)'
  6. Deactivate the Environment: When you are finished, deactivate the environment:

    conda deactivate

Code Example (Verification):

import tensorflow as tf
print("TensorFlow version:", tf.__version__)

2. Installing TensorFlow using Docker

Docker provides a containerization platform that allows you to run applications in isolated environments. This ensures consistency across different systems.

Explanation:

Docker containers package all the necessary dependencies, libraries, and configurations into a single unit. This is beneficial for reproducibility and deployment, as the application will run consistently regardless of the host environment.

Steps:

  1. Install Docker: If you don’t have Docker installed, install it using the following commands:

    sudo dnf install -y docker
    sudo systemctl start docker
    sudo systemctl enable docker
  2. Pull the TensorFlow Docker Image: Pull the official TensorFlow Docker image from Docker Hub. TensorFlow provides images with different configurations, including CPU-only and GPU-enabled versions.

    For CPU-only:

    docker pull tensorflow/tensorflow:latest

    For GPU support (requires NVIDIA drivers and the NVIDIA Container Toolkit):

    docker pull tensorflow/tensorflow:latest-gpu
  3. Run the Docker Container: Run the Docker container with the appropriate options.

    For CPU-only:

    docker run -it tensorflow/tensorflow:latest bash

    For GPU support:

    docker run --gpus all -it tensorflow/tensorflow:latest-gpu bash

    The -it flags allow you to interact with the container in an interactive terminal. The --gpus all flag enables GPU access within the container.

  4. Verify the Installation: Inside the Docker container, verify the TensorFlow installation:

    python -c 'import tensorflow as tf; print(tf.__version__)'
  5. Accessing Files: You can mount directories from your host machine into the container to access your project files. Use the -v flag when running the container:

    docker run -it -v /path/to/your/project:/tf/project tensorflow/tensorflow:latest bash

    This mounts the /path/to/your/project directory on your host machine to /tf/project inside the container.

Code Example (Docker):

Here’s how you’d typically run a simple TensorFlow script within a Docker container after mounting your project directory:

  • Assuming you have a file named test.py in /path/to/your/project on your host machine.

  • The test.py file contains:

import tensorflow as tf
print("TensorFlow version:", tf.__version__)
hello = tf.constant('Hello, TensorFlow!')
tf.print(hello)
  • Run the container:
docker run -it -v /path/to/your/project:/tf/project tensorflow/tensorflow:latest bash
  • Inside the container, navigate to the mounted directory and run the script:
cd /tf/project
python test.py

These two methods offer alternative routes to Install TensorFlow on Rocky Linux 8, each with its advantages. Conda is great for managing complex project dependencies, while Docker ensures consistency and reproducibility across environments. Choose the method that best suits your specific needs and workflow.

Leave a Reply

Your email address will not be published. Required fields are marked *