Skip to content

Install Python3 and required modules

Niels Korschinsky edited this page Feb 23, 2022 · 13 revisions

Install and configure Python3

This part of the install instruction is about installing Python3 as an alternative install to the Python 2.7 version required of yum.

SPPMon requires at least Python version 3.8.2 or a newer version.

Installation

  1. Verify the installed Python version.
    If it is already version >3.8, you can skip the installation and continue with the requirements below.

    which python
    /usr/bin/python -V
    Python 2.7.5

    If this does not show a python path or version, any further install might be troublesome.
    Please stop now and read the troubleshooting install instructions first.

  2. Verify if gcc is installed
    GCC is part of the Red Hat Enterprise Linux Development Tools. Install the tool when it's not available on the system.
    gcc --version

    If it is missing, install it via yum:
    sudo yum install gcc

  3. Install development libraries and packages

    sudo yum -y groupinstall "Development Tools"
    sudo yum -y install openssl-devel bzip2-devel libffi-devel
    sudo yum -y install wget
  4. Download and install Python 3.9.6 package

    mkdir /tmp/python396
    cd /tmp/python396/
    wget --no-check-certificate https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz
    
    cd /tmp/python396/
    tar -xvf Python-3.9.6.tgz
  5. Compile the Python package

    cd /tmp/python396/Python-3.9.6
     
    sudo ./configure
    sudo make altinstall
  6. Verify if the new Python version was installed

    python3.9 -V
    Python 3.9.6
    pip3.9 --version
    pip 21.2.4 from /usr/lib/python3.9/site-packages/pip (python 3.9)

Define alternatives to switch between Python 2.7 and Python 3.9

  1. Set Python3.9 as alternative

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 2
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
    sudo update-alternatives --set python /usr/bin/python2.7
  2. Verify current selection

    update-alternatives --display python
    python - status is manual.
    link currently points to /usr/bin/python2.7
    /usr/bin/python2.7 - priority 1
    /usr/bin/python3.9 - priority 2
    Current `best' version is /usr/bin/python3.9.
  3. Create system link to python version 3.9
    sudo ln -sf "/usr/local/bin/python3.9" "/usr/bin/python3"
    sudo ln -sf "/usr/local/bin/pip3.9" "/usr/bin/pip3"

  4. Verify Switch
    python3 -V

Install required python packages (requirements.txt)

The SPPMon tool requires some additional Python modules that can be installed using pip. The required modules are specified in the file spectrum-protect-sppmon/python/requirements.txt, which is part of the SPPMon source code.

  1. Upgrade pip version
    sudo -H python3 -m pip install --upgrade pip

  2. Install required packages sudo -H python3 -m pip install -U -r "./python/requirements.txt"

Troubleshooting Python3 Install

Any errors while installing python will cause SPPMon not to work. It is important to resolve them before continuing the install process. Common errors are dependencies issues with pip, $PYTHONHOME, and the default python2.7 installation.

which python does not find python

In this case, a regular install will not work and cause dependencies issues with pip or python itself. In the worst case, a system reset to a snapshot before the install can be the best option. Restart the install process manually.

  1. Execute steps 2 and 3 of the section Installation.
  2. Use yum to install python3.9: yum install python3.9 instead. Any Python 3.9.* is OK.
  3. Check python install by using which python3.9
  4. Create a system link to python3 as described in defining the alternatives section steps 3 and 4.
  5. Install python3-devel tools: yum install python3-devel
  6. Continue regularly with installing the required python packages

If using the install script, you may continue from the INFLUX_SETUP point. See skipping installation steps for more information.

Clone this wiki locally