Using different Python versions

The installation instructions assume that a recent enough version of Python can be installed using APT. As sometimes this is not the case, and updating the whole operating system is not always an option, Python can usually be built from source to get a more recent version in addition to the system installation of Python.

Compiling Python from source

First, some additional build dependencies need to be installed:

sudo apt install make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

The source of the desired Python version can then be downloaded from the Python download page, e.g. by using wget:

wget https://www.python.org/ftp/python/3.x.y/Python-3.x.y.tgz

Note

When compiling from source, it is usually recommended to use the latest Python version supported by Kadi4Mat, which currently corresponds to version 3.12.

Afterwards, the source package can be extracted and built using make. Using the -j flag of make speeds up compilation by making use of <n> multiple jobs in parallel, which usually should correspond to the number of cores available:

tar -xf Python-3.x.y.tgz
cd Python-3.x.y
./configure --enable-optimizations --with-lto
make -j <n>

Note that this may take a bit. Once built, in order to install the compiled binary as an alternative to the one already installed on the system, the altinstall target can be used:

Warning

Make sure to actually use the altinstall target instead of install, as the latter may have unintended side effects.

sudo make altinstall

This will install the Python binary as python3.x, depending on the chosen version, which can be verified by running:

python3.x --version

Updating existing installation

When updating Python in existing installations, the existing virtual environment where Kadi4Mat is installed needs to be recreated, e.g. when using a structure as described in the installation instructions:

Note

It is recommended to stop the application and some of its related services before performing all following steps, similar to when performing an update.

sudo su - kadi                   # Switch to the kadi user
rm -rf ${HOME}/venv              # Remove the old virtual environment
python3.x -m venv ${HOME}/venv   # Create the new virtual environment
source ${HOME}/venv/bin/activate # Activate the new virtual environment
pip install wheel                # Install the wheel package
pip install -U pip               # Make sure the newest version of pip is being used
pip install kadi                 # Install the application again

When using server configuration files such as described in the installation instructions for Apache and/or uWSGI, some paths defined in these files referring to the installed kadi Python package may need to be updated accordingly. An easy way to do this is to regenerate these files using the Kadi CLI:

sudo su - kadi    # Switch to the kadi user
kadi utils apache # Generate and print a basic configuration for Apache
kadi utils uwsgi  # Generate and print a basic configuration for uWSGI

The generated content can then be compared with the corresponding configuration files in /etc/apache2/sites-available/kadi.conf and /etc/kadi-uwsgi.ini (when using the structure as described in the installation instructions) to update them accordingly.