*  Informatique / Python / Build Python with Mayavi 4.6.2 on Linux distributions

        * Required system packages
        * Python : compilation and installation
        * Installing PyQt5
        * Installing PySide2 (optional)
        * Configuring and testing Mayavi for Python

pict pict

In this section we explain how to install Mayavi Python package (from PyPI) for several versions of Python on some Linux distributions.
The steps are the following:

The installation process described here was succesfully tested on:



Linux Python


CentOS 7.5 PyQt5: 3.5.6, 3.6.7
PySide2: 2.7.15


Debian 9.5 PyQt5: 3.5.6, 3.6.7
PySide2: 2.7.15


Fedora 29 PyQt5: 3.5.6, 3.6.7
PySide2: 2.7.15


openSUSE 29 PyQt5: 3.5.6, 3.6.7
PySide2: 2.7.15


Ubuntu 18.04 PyQt5: 3.5.6, 3.6.7
PySide2: 2.7.15


On the 15th November, 2018, the installation process does not work with

*  Required system packages

Before we can compile Python sources, we install (as root) some system packages. Other packages than those suggested below may be necessary depending on the configuration of your system.

*  Python : compilation and installation

We assume the installation directory to be /fcopt. This directory is writable for me, otherwise one has to be root for install process. The directory ~/compil is used as working directory.
The following compilation/installation commands are given for Python 3.6.7 version. To use another version, one only has to set PYVER variable. The PYDIR variable contains /fcopt/PYTHON/3.6.7 which is the installation directory and the CDIR variable contains ~/compil which is the compilation directory.

PYVER=3.6.7 
CDIR=~/compil 
DIR=/fcopt 
PYDIR=$DIR/PYTHON/$PYVER 
mkdir -p $CDIR 
cd $CDIR 
# downloading 
wget https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tar.xz 
# extracting 
tar -Jxf Python-$PYVER.tar.xz 
cd Python-$PYVER 
./configure --enable-shared --enable-optimizations  --with-ensurepip=install --prefix=$PYDIR

Thereafter the make command is used by using 8 threads (ususally use as maximum the number of core of your computer)

 make -j 8

On CentOS 7.5 with version 3.7.0 of Python, I need to only use one thread ( python missing builtin ’runpy’ message...)

It is important to ensure that there are no important missing modules by reading last lines (before tests starting with –enable-optimizations option) of the output of previous make command. For example:

... 
Python build finished, but the necessary bits to build these modules were not found: 
_bsddb             bsddb185           dl 
imageop            sunaudiodev 
To find the necessary bits, look in setup.py in detect_modules() for the module’s name. 
...

These missing modules are not not needed in the following (and they are obsolete!).
If some system packages are installed to prevent missing modules one has to rerun the configure command following by the make command.
At last one can install Python under $PYDIR directory:
make install

Thereafter one can update PIP:

$PYDIR/bin/pip${VERSION:0:1} install --upgrade pip

or
wget https://bootstrap.pypa.io/get-pip.py 
$PYDIR/bin/python${VERSION:0:1} get-pip.py

To correctly use and test this installed Python version, we update some environment variables:

PYVER=3.6.7 
export PATH=$PYDIR/bin:/usr/bin:/bin 
export PYTHONPATH=$PYDIR/lib/python${PYVER%.*}/site-packages 
export LD_LIBRARY_PATH=$PYDIR/lib

With PYVER=3.6.7, ${PYVER%.*} is 3.6 and ${PYVER%%.*} is 3.
Thereafter one can run python by using python3 command and pip by using pip3 command. With Python 2 version, we use python2 and pip2 commands.

*  Installing PyQt5

$PYDIR/bin/pip${PYVER%%.*} install PyQt5

When this package is not available on PyPI(for example with Python 2.7.15, november 2018) one can install PySide2 package with Mayavi. One can run the python code pyqt5_window.py (656 bytes) :
wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/pyqt5_window.py 
$PYDIR/bin/python${PYVER%%.*} pyqt5_window.py

*  Installing PySide2 (optional)

I install this package when PyQt5 Python package is not available on PyPI.

$PYDIR/bin/pip${PYVER%%.*} install PySide2

On november 2018, the version 5.11.2 is installed. One can run the python code pyside2_t10.py (6492 bytes) :
wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/pyside2_t10.py 
$PYDIR/bin/python${PYVER%%.*} pyside2_t10.py

*  Configuring and testing Mayavi for Python

We set some environment variables. If PyQt5 Python package is installed:

export ETS_TOOLKIT= 
export QT_API=pyqt5

Otherwise, if PySide2 Python package is installed:
export ETS_TOOLKIT= 
export QT_API=pyside2

To install the mayavi package one can do:

$PYDIR/bin/pip${PYVER%%.*} install PyQt5

To quickly test the mayavi package, one can run the python code mayavi_boy.py (774 bytes) .

wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/mayavi_boy.py 
$PYDIR/bin/python${PYVER%%.*} mayavi_boy.py