*  Informatique / Python / Build Python 2.7.x/3.6.x with Mayavi 4.5.1(dev) and PyQt5 on centOS 7

        * Required packages
        * Python : compilation and installation
        * Installing VTK
        * Installing PyQt5
        * Installing matplotlib, numpy, ...
        * Installing mayavi

pict pict

In this section I explain how to install Mayavi 4.5.1 (development version) on Python 2.7.x, 3.5.x or 3.6.x on CentOS 7.
The steps are the following:

The installation process described here was succesfully tested with Python 2.7.14, 3.5.5 and 3.6.4.

To use Mayavi 4.5.0 python package, the version 4 of PyQt is needed: version 5 is not supported in this version of Mayavi. To use PyQt version 5 one has to install Mayavi 4.5.1 (development version on march 2018), pyface (>= 5.2.0) and traitsui (>=5.2.0)

*  Required packages

On my CentOS 7 computer, I need to install (as root) the following system packages to compile Python

sudo yum install gcc gcc-c++ gcc-gfortran ncurses-devel tk-devel gdbm-devel \ 
         readline-devel sqlite-devel bzip2-devel openssl-devel xz-devel

*  Python : compilation and installation

I 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.4 version. To use another version, one only has to set PYVER variable. The PYDIR variable contains /fcopt/PYTHON/3.6.4 which is the installation directory and the CDIR variable contains ~/compil which is the compilation directory.

PYVER=3.6.4 
CDIR=~/compil 
DIR=/fcopt 
PYDIR=$DIR/PYTHON/$PYVER 
mkdir -p $CDIR 
cd $CDIR 
wget https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tar.xz 
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

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. There is what I obtain on my computer:

... 
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!). Some other missing modules can be found. There are some of them and the corresponding CentOS packages to install with sudo yum install <package_name> command:

missing modules packages


_tkinter tk-devel
_gdbm and _dbm gdbm-devel
_sqlite3 sqlite-devel
_lzma xz-devel

If some CentOS packages are installed to prevent missing modules one has to rerun the configure command the make command.
At last one can install Python under $PYDIR directory

make install

On March 2018, packages installed with this Python installation are pip-9.0.1 and setuptools-28.8.0.
To correctly use and test this installed python version
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.4, ${PYVER%.*} is 3.6 and ${PYVER%%.*} is 3.
To test the installation, I use pip to install ipython package:
$PYDIR/bin/pip${PYVER%%.*} install ipython

*  Installing VTK

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

On march 2018, the version 8.1.0 is installed. One can run the python code sphere.py (700 bytes) to test the VTK Python package installation (with PATH, PYTHONPATH and LD_LIBRARY_PATH correctly sets):
wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/sphere.py 
$PYDIR/bin/python${PYVER%%.*} sphere.py

*  Installing PyQt5

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

On march 2018, the version 5.10.1-5 is installed. 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 matplotlib, numpy, ...

I choose to install matplotlib package after the installation of PyQt.

$PYDIR/bin/pip${PYVER%%.*} install numpy scipy matplotlib

*  Installing mayavi

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

The mayavi-4.5.0 python package is now installed (march 2018). If the installed version is great than or equal to 4.5.1 (not yet available on march 2018) then nothing else is needed.
Otherwise, one has to upgrade version 4.5.0 to a version >= 4.5.1 by using Enthought developement version of Mayavi, pyface and traitsui Python packages.
$PYDIR/bin/pip${PYVER%%.*} install git+https://github.com/enthought/mayavi.git 
$PYDIR/bin/pip${PYVER%%.*} install git+https://github.com/enthought/pyface.git 
$PYDIR/bin/pip${PYVER%%.*} install git+https://github.com/enthought/traitsui.git

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