Wednesday, 7 August 2024

python 3.9 installation where no iontenet with pip

Installing Python 3.9 on Red Hat 8.6 Without Internet Access

This document outlines two methods to install Python 3.9 on an offline Red Hat 8.6 machine using yum.


Method 1: Install Python 3.9 from RPM Packages

Step 1: Download Python 3.9 RPMs on an Internet-Connected Machine

On a machine with internet access, download Python 3.9 and its dependencies using yum:

yum install --downloadonly --downloaddir=/tmp/python39 python39 python39-libs python39-devel python39-pip

This will save all required RPMs in /tmp/python39/.

Step 2: Transfer the RPMs to the Offline Machine

Use scp, USB, or another method to copy the downloaded RPMs to the offline machine:

scp -r /tmp/python39 user@offline-machine:/home/user/

Step 3: Install Python 3.9 and pip Using yum Locally

On the offline machine, navigate to the directory containing the copied RPMs:

cd /home/user/python39

Then install all RPMs using yum:

sudo yum localinstall *.rpm -y

Step 4: Verify Installation

Check the installed version:

python3.9 --version
pip3.9 --version

Method 2: Build Python 3.9 from Source

If RPM packages are not available, you can compile Python manually.

Step 1: Download Python Source Code

On an internet-connected machine, download the Python 3.9 source code:

wget https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz

Step 2: Transfer to the Offline Machine

Copy the file to the offline machine using scp or a USB drive:

scp Python-3.9.18.tgz user@offline-machine:/home/user/

Step 3: Install Required Build Dependencies

On an internet-connected machine, download required dependencies:

yum install --downloadonly --downloaddir=/tmp/dependencies gcc make bzip2 bzip2-devel zlib-devel xz-devel libffi-devel

Transfer these RPMs to the offline machine and install them:

cd /home/user/dependencies
sudo yum localinstall *.rpm -y

Step 4: Extract and Compile Python

On the offline machine, extract the Python source code:

cd /home/user/
tar xvf Python-3.9.18.tgz
cd Python-3.9.18

Then, configure and compile:

./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall

Step 5: Install pip

After installing Python, download and install pip manually:

wget https://bootstrap.pypa.io/get-pip.py
python3.9 get-pip.py

Step 6: Verify Installation

Check the installed version:

python3.9 --version
pip3.9 --version

Conclusion

  • Method 1 (Using RPMs) is faster and preferred if prebuilt RPMs are available.
  • Method 2 (Compiling from Source) takes longer but ensures compatibility if RPMs are not an option.

Ensure all dependencies are transferred before proceeding with the installation.

No comments:

Post a Comment