Saturday, 2 December 2023

Install Python 3.10 where there is no internet

To install Python 3.10 on your EC2 instance without internet access, you can use your Windows machine with connectivity to the EC2 instance to download the necessary files and transfer them to the EC2 instance. Here's how you can do it step by step:


1. Check Current Python Version on EC2

On your EC2 instance, check if Python is installed and its version:

bash

 

python3 --version


2. Download Python 3.10 on Your Windows Machine

  1. Visit the official Python website: Python 3.10 Downloads.
  2. Download the source tarball (Python-3.10.x.tgz) and the required dependencies for offline installation.

3. Download Required Dependencies

Since your EC2 instance runs Red Hat 8.6:

  1. Identify the dependencies for Python 3.10 (e.g., gcc, make, zlib-devel, openssl-devel, etc.).
  2. On your Windows machine, download these RPM packages from the Red Hat Package Manager or using a CentOS 8/RHEL 8 system that matches your EC2 instance's configuration.

4. Transfer Files to EC2

  1. Install an SCP client on your Windows machine, such as WinSCP or use an SCP command.
  2. Transfer the downloaded files to your EC2 instance:

bash

 

scp -i your-key.pem Python-3.10.x.tgz user@ec2-instance-ip:/path/to/destination


5. Install Python 3.10

On your EC2 instance:

  1. Extract the tarball:

bash

 

tar -xvzf Python-3.10.x.tgz

cd Python-3.10.x

  1. Install dependencies from RPM files:

bash

 

sudo rpm -ivh /path/to/dependencies/*.rpm

  1. Build and install Python:

bash

 

./configure --enable-optimizations

make

sudo make install

  1. Verify the installation:

bash

 

python3.10 --version


6. Set Python 3.10 as Default (Optional)

If you want to use Python 3.10 as the default python3:

bash

 

sudo alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1

sudo alternatives --config python3


7. Troubleshooting

If you encounter any missing dependency errors, ensure all required RPMs are downloaded and transferred to the EC2 instance.

Let me know if you need additional help!

 

 

 

Let me clarify Point 3: Download Required Dependencies for you.

Why Dependencies Are Needed?

To compile and install Python 3.10 from source, your EC2 instance requires specific libraries and tools, such as:

  • A C compiler (like gcc).
  • Libraries for compression, SSL, and other Python features (zlib-devel, openssl-devel, etc.).

Since your EC2 instance does not have internet access, these dependencies need to be downloaded on your Windows machine and transferred to the EC2 instance.


Steps to Download Required Dependencies

Step 1: Identify Required Packages

Python 3.10 typically requires:

  • gcc (for compiling the source code)
  • make
  • zlib-devel
  • openssl-devel
  • libffi-devel
  • bzip2-devel
  • sqlite-devel
  • Other optional libraries for Python features

Step 2: Use a System with Internet Access

Since you're on a Windows machine, you can either:

  1. Use a Linux VM with internet connectivity (e.g., Ubuntu or CentOS running in VirtualBox or WSL).
  2. Access a package repository to download these dependencies as .rpm files.

Step 3: Download RPM Files

  1. Use RPMFind.net to locate and download the appropriate RPM files for Red Hat 8.6 (the OS running on your EC2 instance). For example:
    • Search for gcc and download its .rpm.
    • Search for openssl-devel, zlib-devel, etc.
    • Ensure all dependencies of these packages (sub-dependencies) are also downloaded.
  2. Alternatively, if you have access to a system with yum (like another Red Hat-based system):

bash

 

yumdownloader gcc make zlib-devel openssl-devel libffi-devel bzip2-devel sqlite-devel

This command downloads the .rpm files without installing them.

Step 4: Transfer RPM Files to EC2

  1. Use an SCP tool (e.g., WinSCP) or scp command to copy the RPM files to the EC2 instance:

bash

 

scp -i your-key.pem /path/to/rpm/files/*.rpm user@ec2-instance-ip:/path/to/destination

Step 5: Install RPMs on EC2

On the EC2 instance:

  1. Navigate to the directory where you copied the .rpm files:

bash

 

cd /path/to/rpm/files

  1. Install the packages:

bash

 

sudo rpm -ivh *.rpm

If there are dependency errors, ensure all required sub-dependencies are also present and install them.


This ensures your EC2 instance has all the tools and libraries to compile Python 3.10 successfully.



Option 1: Use a Compatible Repository

Use CentOS 8 Stream or Red Hat 8 compatible RPMs. These are often available from trusted repositories like:

  1. CentOS Vault (CentOS 8 is binary-compatible with Red Hat 8):
    https://vault.centos.org/
  2. Red Hat CDN (requires subscription):
    If you have a Red Hat Developer subscription, you can download packages from Red Hat's official repository using a Red Hat system.

Search for the following package names:

  • gcc
  • gcc-c++
  • glibc-devel
  • glibc-headers
  • libgcc

Option 2: Use a Yum-Enabled System

If you have a CentOS or Red Hat system with internet access:

  1. Install yum-utils:

bash

 

sudo yum install yum-utils

  1. Download the required packages for offline use:

bash

 

yumdownloader gcc glibc-devel zlib-devel openssl-devel libffi-devel bzip2-devel sqlite-devel

  1. Transfer these .rpm files to your Windows machine or directly to the EC2 instance.

 wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/gcc-8.5.0-4.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/AppStream/x86_64/os/Packages/gcc-c++-8.5.0-4.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/glibc-devel-2.28-211.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/libffi-devel-3.1-22.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/make-4.2.1-11.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/bzip2-devel-1.0.6-26.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/zlib-devel-1.2.11-19.el8.x86_64.rpm

wget https://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/openssl-devel-1.1.1k-5.el8.x86_64.rpm


 


No comments:

Post a Comment