Discover Centmin Mod today
Register Now

CentOS 7.x Custom Python 3.7, 3.8, 3.9 & 3.10 RPM Builds For CentOS 7

Discussion in 'Beta release code' started by eva2000, Feb 5, 2022.

Thread Status:
Not open for further replies.
  1. eva2000

    eva2000 Administrator Staff Member

    54,485
    12,208
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,777
    Local Time:
    7:44 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    CentOS 7 by default uses Python 2.7 and has side by side install support up to Python 3.6 via YUM repository RPM packages. For Python 3.7 and higher, you'd need to source compile and that can take quite some time ie. on a dedicated Intel Core i7 4790K 4.2+ GHz server it would take between 15-20 minutes to compile.

    Recently, while installing fonttools for Xenforo usage, I came across fonttools Python minimum version requirements. For their latest fonttools v4.29, it required Python 3.7 this is because fonttools v4.28+ and higher switched to Python 3.7 minimum version requirement. If you install fonttools via Python 3.6, you will install fonttools v4.27.1. That's fine for Xenforo usage.

    However, I asked myself what if a specific Python app/tool required Python 3.7? You can source compile as outlined on Centmin Mod blog article at CentOS 7 Python 2.7 Upgrade Deprecation Message - End Of Life January 1st, 2020 - Centmin Mod Blog and that should be fine for most folks.

    But what if I created custom Python RPM builds for Python 3.7, 3.8, 3.9 and 3.10? So this is what I did as a test to see if it works as it should and so far looks good :)

    Custom Python 3.7+ RPM Builds



    The RPMs will install to /opt/pythonXXX where XXX is version prefix like 3.7, 3.8, 3.9, 3.10 so as to not conflict with any other YUM/RPM based installs of Python. Best practices for Python versions other than Python 2.7 for CentOS 7, is to install your Python apps within Python virtual environments like outlined at CentOS 7 Python 2.7 Upgrade Deprecation Message - End Of Life January 1st, 2020 - Centmin Mod Blog.


    These include the following versions:
    • python 3.7.12
    • python 3.8.12
    • python 3.9.10
    • python 3.10.2
    Code (Text):
    yum -q list centmin-python*
    Installed                  Packages
    centmin-python3.10.x86_64  3.10.2-1.el7  @/centmin-python3.10-3.10.2-1.el7.x86_64
    centmin-python3.7.x86_64   3.7.12-1.el7  @/centmin-python3.7-3.7.12-1.el7.x86_64
    centmin-python3.8.x86_64   3.8.12-1.el7  @/centmin-python3.8-3.8.12-1.el7.x86_64
    centmin-python3.9.x86_64   3.9.10-1.el7  @/centmin-python3.9-3.9.10-1.el7.x86_64
    

    Code (Text):
    /opt/python3.7/bin/python3.7 --version
    Python 3.7.12
    
    /opt/python3.8/bin/python3.8 --version
    Python 3.8.12
    
    /opt/python3.9/bin/python3.9 --version
    Python 3.9.10
    
    /opt/python3.10/bin/python3.10 --version
    Python 3.10.2
    

    Python 3.7


    Code (Text):
    yum -q info centmin-python3.7-3.7.12
    Installed Packages
    Name        : centmin-python3.7
    Arch        : x86_64
    Version     : 3.7.12
    Release     : 1.el7
    Size        : 182 M
    Repo        : installed
    From repo   : /centmin-python3.7-3.7.12-1.el7.x86_64
    Summary     : python 3.7.12 for centminmod.com LEMP stack python 3.7.12
    URL         : https://centminmod.com
    License     : unknown
    Description : python 3.7.12 for centminmod.com LEMP stacks

    Code (Text):
    rpm -ql centmin-python3.7-3.7.12 | grep '/bin/'
    /opt/python3.7/bin/2to3-3.7
    /opt/python3.7/bin/idle3.7
    /opt/python3.7/bin/pydoc3.7
    /opt/python3.7/bin/python3.7
    /opt/python3.7/bin/python3.7m
    /opt/python3.7/bin/python3.7m-config
    /opt/python3.7/bin/pyvenv-3.7


    python 3.7 virtual environment example for installing fonttools


    Code (Text):
    python_ver=3.7.12
    python_prefixver=$(echo $python_ver | cut -d . -f1,2)
    project_name=project1
    mkdir -p /home/python_projects/$project_name
    /opt/python${python_prefixver}/bin/python${python_prefixver} -m venv /home/python_projects/$project_name
    source /home/python_projects/$project_name/bin/activate
    
    # pip doesn't like ccache so disable it
    export CC='gcc'
    export CXX="g++"
    
    # pip needs a tmp directory that doesn't have noexec restrictions
    mkdir -p /home/piptmp
    chmod 1777 /home/piptmp
    export TMPDIR=/home/piptmp
    
    pip install -U pip
    pip --version
    python -m pip install fonttools --verbose --force
    python -m pip install fonttools[woff] --verbose --force
    updatedb
    locate pyftsubset

    Example output
    Code (Text):
    source /home/python_projects/$project_name/bin/activate
    
    pip install -U pip
    Collecting pip
      Downloading pip-22.0.3-py3-none-any.whl (2.1 MB)
        |████████████████████████████████| 2.1 MB 45.0 MB/s
    Installing collected packages: pip
      Attempting uninstall: pip
       Found existing installation: pip 20.1.1
       Uninstalling pip-20.1.1:
         Successfully uninstalled pip-20.1.1
    Successfully installed pip-22.0.3
    
    pip --version
    pip 22.0.3 from /home/python_projects/project1/lib/python3.7/site-packages/pip (python 3.7)
    
    python -m pip install fonttools --verbose --force
    Using pip 22.0.3 from /home/python_projects/project1/lib/python3.7/site-packages/pip (python 3.7)
    Collecting fonttools
      Downloading fonttools-4.29.1-py3-none-any.whl (895 kB)
        ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 895.5/895.5 KB 69.6 MB/s eta 0:00:00
    Installing collected packages: fonttools
      changing mode of /home/python_projects/project1/bin/fonttools to 755
      changing mode of /home/python_projects/project1/bin/pyftmerge to 755
      changing mode of /home/python_projects/project1/bin/pyftsubset to 755
      changing mode of /home/python_projects/project1/bin/ttx to 755
    Successfully installed fonttools-4.29.1
    
    python -m pip install fonttools[woff] --verbose --force
    Using pip 22.0.3 from /home/python_projects/project1/lib/python3.7/site-packages/pip (python 3.7)
    Collecting fonttools[woff]
      Using cached fonttools-4.29.1-py3-none-any.whl (895 kB)
    Collecting zopfli>=0.1.4
      Downloading zopfli-0.1.9-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (113 kB)
        ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 113.4/113.4 KB 40.2 MB/s eta 0:00:00
    Collecting brotli>=1.0.1
      Downloading Brotli-1.0.9-cp37-cp37m-manylinux1_x86_64.whl (357 kB)
        ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 357.2/357.2 KB 68.9 MB/s eta 0:00:00
    Installing collected packages: zopfli, brotli, fonttools
      Attempting uninstall: fonttools
       Found existing installation: fonttools 4.29.1
       Uninstalling fonttools-4.29.1:
         Removing file or directory /home/python_projects/project1/bin/fonttools
         Removing file or directory /home/python_projects/project1/bin/pyftmerge
         Removing file or directory /home/python_projects/project1/bin/pyftsubset
         Removing file or directory /home/python_projects/project1/bin/ttx
         Removing file or directory /home/python_projects/project1/lib/python3.7/site-packages/fontTools/
         Removing file or directory /home/python_projects/project1/lib/python3.7/site-packages/fonttools-4.29.1.dist-info/
         Removing file or directory /home/python_projects/project1/share/man/man1/
         Successfully uninstalled fonttools-4.29.1
      changing mode of /home/python_projects/project1/bin/fonttools to 755
      changing mode of /home/python_projects/project1/bin/pyftmerge to 755
      changing mode of /home/python_projects/project1/bin/pyftsubset to 755
      changing mode of /home/python_projects/project1/bin/ttx to 755
    Successfully installed brotli-1.0.9 fonttools-4.29.1 zopfli-0.1.9
    
    locate pyftsubset
    /home/python_projects/project1/bin/pyftsubset


    Directly calling python from virtual environment
    Code (Text):
    project_name=project1
    /home/python_projects/${project_name}/bin/pip --version
    pip 22.0.3 from /home/python_projects/project1/lib/python3.7/site-packages/pip (python 3.7)
    
    /home/python_projects/${project_name}/bin/python --version
    Python 3.7.12


    Python 3.8


    Code (Text):
    yum -q info centmin-python3.8-3.8.12
    Installed Packages
    Name        : centmin-python3.8
    Arch        : x86_64
    Version     : 3.8.12
    Release     : 1.el7
    Size        : 234 M
    Repo        : installed
    From repo   : /centmin-python3.8-3.8.12-1.el7.x86_64
    Summary     : python 3.8.12 for centminmod.com LEMP stack python 3.8.12
    URL         : https://centminmod.com
    License     : unknown
    Description : python 3.8.12 for centminmod.com LEMP stacks

    Code (Text):
    rpm -ql centmin-python3.8-3.8.12 | grep '/bin/'
    /opt/python3.8/bin/2to3-3.8
    /opt/python3.8/bin/idle3.8
    /opt/python3.8/bin/pip3.8
    /opt/python3.8/bin/pydoc3.8
    /opt/python3.8/bin/python3.8
    /opt/python3.8/bin/python3.8-config


    Python 3.9


    Code (Text):
    yum -q info centmin-python3.9-3.9.10
    Installed Packages
    Name        : centmin-python3.9
    Arch        : x86_64
    Version     : 3.9.10
    Release     : 1.el7
    Size        : 246 M
    Repo        : installed
    From repo   : /centmin-python3.9-3.9.10-1.el7.x86_64
    Summary     : python 3.9.10 for centminmod.com LEMP stack python 3.9.10
    URL         : https://centminmod.com
    License     : unknown
    Description : python 3.9.10 for centminmod.com LEMP stacks

    Code (Text):
    rpm -ql centmin-python3.9-3.9.10 | grep '/bin/'
    /opt/python3.9/bin/2to3-3.9
    /opt/python3.9/bin/idle3.9
    /opt/python3.9/bin/pip3.9
    /opt/python3.9/bin/pydoc3.9
    /opt/python3.9/bin/python3.9
    /opt/python3.9/bin/python3.9-config


    Python 3.10



    Requires OpenSSL 1.1.1 which CentOS 7 doesn't use. But Centmin Mod Nginx uses OpenSSL 1.1.1, so use that OpenSSL 1.1.1 version to build Python 3.10

    Code (Text):
    yum -q info centmin-python3.10-3.10.2
    Installed Packages
    Name        : centmin-python3.10
    Arch        : x86_64
    Version     : 3.10.2
    Release     : 1.el7
    Size        : 265 M
    Repo        : installed
    From repo   : /centmin-python3.10-3.10.2-1.el7.x86_64
    Summary     : python 3.10.2 for centminmod.com LEMP stack python 3.10.2
    URL         : https://centminmod.com
    License     : unknown
    Description : python 3.10.2 for centminmod.com LEMP stacks

    Code (Text):
    rpm -ql centmin-python3.10-3.10.2 | grep '/bin/'
    /opt/python3.10/bin/2to3-3.10
    /opt/python3.10/bin/idle3.10
    /opt/python3.10/bin/pip3.10
    /opt/python3.10/bin/pydoc3.10
    /opt/python3.10/bin/python3.10
    /opt/python3.10/bin/python3.10-config
     
Thread Status:
Not open for further replies.