Preparing an offline installation of Python 3.4 (+packages) for CentOS 6


We ran into an interesting situation on a legacy system where we were unable to allow outbound traffic on a CentOS 6 server to the internet, yet we needed to install Python 3.4 and the 'requests' library on the server.

Approach / Summary

In order to get the RPMs and python packages I needed, I setup a vanilla CentOS 6 VM with the EPEL repository enabled. Using EPEL ensures compatibility for this older version of centos. Once Python 3.4 was installed, easy_install was used to pull down the requests library. With the packages cached on my VM, it was easy to move them to the other server

Preparing the RPMs

  • Install CentOS 6 on a local VM
  • Edit the /etc/yum.conf file to cache the RPM files:

    keepcache=0

  • yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
  • yum install python34 python34-setuptools
  • Use scp/sftp to copy the RPMs off the VM

Prepare the python requests package

  • easy_install-3.4 requests
  • tar czf site-packages.tgz /usr/lib/python3.4/site-packages

Install on the Remote Machine

1) First, I created a simple script to do the installation:

#!/bin/bash

# Install the RPMs
rpm -ivh python34*.rpm

# Deploy the python libraries
tar xf site-packages.tgz -C /usr/lib/python3.4

2) Next, I copied the RPMs and the python site-packages to the CentOS 6 system without internet access

3) Run the script to install the RPMs and install the python packages

Test the Installation

The goal was to get the Python 3.4 with the requests library installed and functioning on a CentOS 6 system that has no external/public internet access. To verify this, try running a simple program that uses requests:

  • python3.4

    Python 3.4.5 (default, Dec 11 2017, 16:57:19)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
  • import requests

  • response = requests.get('https://google.com')

  • response.text

If you don't get an error back (and you get the html of the page you requested) it means it worked. While I specified google.com above, in reality I used a different http endoint that was available inside our network to test this out.