Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Deploying Python 3.9 on Offline CentOS Servers

Tech 1

Deploying applications in an isolated network environment requires preparing all necessary assets on a connected machine before transferring them. This guide outlines the procedure for setting up a Python 3.9 environment and project dependencies on an offline CentOS server.

Phase 1: Resource Preparation (Online Machine)

Begin by preparing a directory structure to store the downloaded system libraries and Python packages.

mkdir -p /opt/pkg_downloads/rpm_deps
mkdir -p /opt/pkg_downloads/python_wheels

Install the utility required to download RPM packages without installing them immediately.

yum install yum-utils -y

Download the necessary compiler and development libraries required for building Python. These dependencies handle compression, encryption, and database support.

yumdownloader --resolve --destdir=/opt/pkg_downloads/rpm_deps \
gcc make \
zlib-devel bzip2-devel \
openssl-devel ncurses-devel \
sqlite-devel readline-devel \
tk-devel libffi-devel

Obtain the Python source code archive from the official repository. For this example, version 3.9.0 is utilized. Extract the archive and compile the binaries.

# Navigate to the source directory
cd /opt/pkg_downloads

# Extract the archive
tar -xvf Python-3.9.0.tgz
cd Python-3.9.0

# Configure installation path and optimize builds
./configure --prefix=/opt/python-3.9 --enable-optimizations

# Compile and install
make && make install

Create symbolic links to ensure the Python binaries are accessible system-wide.

ln -sf /opt/python-3.9/bin/python3.9 /usr/bin/python3
ln -sf /opt/python-3.9/bin/pip3.9 /usr/bin/pip3

Generate a requirements file for your project if one does not exist, then download all project dependencies as wheel files. Wheel files are preferred for offline installation as they are pre-compiled.

# Download dependencies to the local directory
pip3 download -r requirements.txt -d /opt/pkg_downloads/python_wheels

Phase 2: Environment Setup (Offline Machine)

Transfer the directory /opt/pkg_downloads from the online machine to the offline server using portable storage.

Install the system dependencies using the RPM files collected earlier. The --nodeps and --force flags are used to bypass potential circular dependency checks during the bulk install, as the resolver cannot access remote repositories.

cd /opt/pkg_downloads/rpm_deps
rpm -Uvh *.rpm --nodeps --force

Proceed with the compilation and installation of Python on the offline server using the source code.

cd /opt/pkg_downloads
tar -xvf Python-3.9.0.tgz
cd Python-3.9.0

./configure --prefix=/opt/python-3.9 --enable-optimizations
make && make install

ln -sf /opt/python-3.9/bin/python3.9 /usr/bin/python3
ln -sf /opt/python-3.9/bin/pip3.9 /usr/bin/pip3

Verify the Python installation.

python3 --version

Install the Python project dependencies from the local wheel repository without accessing the internet.

pip3 install --no-index --find-links=/opt/pkg_downloads/python_wheels -r requirements.txt

Application Execution

Navigate to the project directory and launch the application.

cd /path/to/project
python3 main.py

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.