Custom installation of Python
Installing Python 3
While AlmaLinux comes with Python 3.6.8 by default, it is a good practice to provide users more recent versions of it.
Python 3 is an example of a non-trivial software package that can be installed across the cluster, which should not be in conflict with the system installation of Python.
There are three necessary tasks to accomplish this:
Install the necessary library dependencies for Python 3 to function on master and the compute nodes
Install the necessary library headers on
masterso Python 3 can be compiled with themCompile Python 3 on
masterand install it into/data/opt/tools/
Note
If GCC is not in your system, install the build environment
[root@master ~]# yum groupinstall "Development Tools"
Start by downloading the a more recent source code package of Python 3 (remember, work as install user):
[install@master ~]$ wget https://www.python.org/ftp/python/3.13.3/Python-3.13.3.tgz
Untar the Python source code, configure it with --prefix=/data/opt/tools/python-3.13.3 and compile it.
This ensures that make install will copy all files into /data/opt/tools/python-3.13.3, which is owned by the install user and therefore doesn’t require sudo/root rights.
[install@master ~]$ tar xvzf Python-3.13.3.tgz
[install@master ~]$ mkdir build-python-3.13.3
[install@master ~]$ cd build-python-3.13.3
[install@master build-python-3.13.3]$ ../Python-3.13.3/configure --prefix=/data/opt/tools/python-3.13.3
[install@master build-python-3.13.3]$ make -j 1
In case of missing dependencies (headers, libraries) the Python build will output what optional modules were not compiled.
The following modules are *disabled* in configure script:
_sqlite3
The necessary bits to build these optional modules were not found:
_bz2 _ctypes _ctypes_test
_curses _curses_panel _dbm
_gdbm _tkinter _uuid
readline
To find the necessary bits, look in configure.ac and config.log.
Checked 112 modules (33 built-in, 67 shared, 1 n/a on linux-x86_64, 1 disabled, 10 missing, 0 failed on import)
Try finding the missing dependencies, install the libraries and their headers via yum and then rebuild.
Take notes on what packages you needed to install as RPM. You will need these notes later!
HINT.
# example, install zlib library and headers
yum install zlib zlib-devel
Note
On RedHat based systems –like AlmaLinux– library packages are usually split up into two parts: one package containing the libraries (e.g. zlib), and another package containing the necessary development headers (e.g. zlib-devel).
Finally, do a make install.
If you look at the first two levels of directories in /data/opt/tools/python-3.13.3, you will see the package provides python3, pip3 and other binaries in /data/opt/tools/python-3.13.3/bin.
[install@master build-python-3.13.3]$ tree -L 2 /data/opt/tools/python-3.13.3
/data/opt/tools/python-3.13.3
├── bin
│ ├── idle3 -> idle3.13
│ ├── idle3.13
│ ├── pip3
│ ├── pip3.13
│ ├── pydoc3 -> pydoc3.13
│ ├── pydoc3.13
│ ├── python3 -> python3.13
│ ├── python3.13
│ ├── python3.13-config
│ └── python3-config -> python3.13-config
├── include
│ └── python3.13
├── lib
│ ├── libpython3.13.a
│ ├── pkgconfig
│ └── python3.13
└── share
└── man
To make this customized software installation usable, we will need to modify some of our environment variables:
[install@master ~]$ export PATH=/data/opt/tools/python-3.13.3/bin:$PATH
[install@master ~]$ export LD_LIBRARY_PATH=/data/opt/tools/python-3.13.3/lib:$LD_LIBRARY_PATH
Setting PATH and LD_LIBRARY_PATH variables will make your python installation usable.
[install@master ~]$ python3
Python 3.13.3 (main, May 30 2025, 05:46:41) [GCC 8.5.0 20210514 (Red Hat 8.5.0-26)] on linux
Type "help", "copyright", "credits" or "license" for more information.
warning: can't use pyrepl: No module named 'msvcrt'
>>>
To enable man to find the new Python 3 man pages in /data/opt/tools/python-3.13.3/share/man update the MANPATH environment variable.
[install@master ~]$ export MANPATH=/data/opt/tools/python-3.13.3/share/man:$MANPATH
For software that need the Python include headers to be visible during compilation one can define CPATH or C_INCLUDE_PATH:
export CPATH=/data/opt/tools/python-3.13.3/include/python3.13:$CPATH
PATHdefines the search path for finding executables in your shell
LD_LIBRARY_PATHdefines the shared library search path the dynamic linker uses at startup
MANPATHdefines the search path for finding man pages
CPATHdefines a global include path for compilers such as
gcc
Installing Python 2
While Python 2 is EOL, let’s assume we have cluster users that require the latest one Python 2 release. Or maybe you want to provide them with optimized builds for your particular cluster.
Follow the steps for Python 3 and install Python 2.7.18 in its own location at /data/opt/tools/python-2.7.18.
Python 2.7.18 can be downloaded from https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz.
Verify your installation works by exporting the necessary environment variables and running python2.
[install@master ~]$ export PATH=/data/opt/tools/python-2.7.18/bin:$PATH
[install@master ~]$ export LD_LIBRARY_PATH=/data/opt/tools/python-2.7.18/lib:$LD_LIBRARY_PATH
[install@master ~]$ export MANPATH=/data/opt/tools/python-2.7.18/share/man:$MANPATH
[install@master ~]$ export CPATH=/data/opt/tools/python-2.7.2/include/python2.7:$CPATH
[install@master ~]$ python2
Python 2.7.18 (default, May 30 2025, 07:46:31)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-26)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>