Informatique / Python / Building Python 2.7.x/3.6.x with Mayavi 4.5.0 on centOS 7
In this section I explain how to install Mayavi 4.5.0 on Python 2.7.x, 3.5.x or 3.6.x (not tested with other versions)
on CentOS 7.
The steps are the following :
- installing some required packages
- compiling and installing Python
- compiling and installing VTK Python wrapper
- compiling and installing PyQt version 4 Python package (version 5 not supported by Mayavi)
- installing Mayavi 4.5.0 Python package
The installation process described here was succesfully tested with Python 2.7.14, 3.5.5 and 3.6.0.
Required packages
On my CentOS 7 computer, I need to install (as root) the following packages to compile Python/VTK/PyQt4
sudo yum install gcc gcc-c++ gcc-gfortran ncurses-devel tk-devel gdbm-devel \
readline-devel sqlite-devel bzip2-devel openssl-devel xz-devel
To compile VTK, one must use cmake version 3 but only version 2.8.12 can be installed by default.
- Download the latest epel-release rpm from http://dl.fedoraproject.org/pub/epel/7/x86_64/. On
march 2018, file is epel-release-7-11.noarch.rpm so
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
- Install epel-release rpm :
sudo rpm -Uvh epel-release*rpm
- Install cmake3 rpm package : On march 2018, the version 3.6.3 of cmake is then installed. Take care, commands are /usr/bin/cmake3,
/usr/bin/ccmake3, ...
For VTK compilation some other packages are required :
sudo yum install mesa-libGL-devel libXt-devel
For PyQt version 4, the package qt4-devel must be installed
sudo yum install qt4-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.4CDIR=~/compilDIR=/fcoptPYDIR=$DIR/PYTHON/$PYVERmkdir -p $CDIRcd $CDIR
wget https://www.python.org/ftp/python/$PYVER/Python-$PYVER.tar.xztar -Jxf Python-$PYVER.tar.xz
cd Python-$PYVER./configure --enable-shared --enable-optimizations --with-ensurepip=install --prefix=$PYDIR
- The option –enable-shared is needed when building VTK python wrapper.
- The option –enable-optimizations ensure to have an optimized version of Python. This option is
time consuming as it requires running a lot of tests (approximatively 30 minutes on my computer).
To quickly try Python compilation process, do not use this option !
- The option –with-ensurepip=install permits the installation of setuptools and pip packages.
Thereafter the make command is used by using 8 threads (ususally use as maximum the number of core of your
computer)
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 dlimageop 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
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:/binexport 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 :
pip${PYVER%%.*} install ipython
The mayavi package requires VTK (with ccmake command) and PyQt package to be installed.
Installing VTK
On march 2018, The lastest version of VTK is 8.1.0. I choose as installation directory
/fcopt/VTK/vtk8.1.0-py$PYVER which is writeable for me. In the following commands, the DIR, CDIR, PYVER,
PYDIR variables are those used for the previously Python installation. There are some remarks on the following
commands :
- ${VTKVER%.*} contains the characters before last point in $VTKVER variable so if $VTKVER is 8.1.0,
${VTKYVER%%.*} contains 8.1.
- The -DVTK_LEGACY_SILENT:BOOL=ON is used to avoid some warning messages when using vtk
python package as Generic Warning : ...was deprecated for VTK 8.1 and will be removed in a
future version.
cd $CDIRVTKVER=8.1.0VTKDIR=$DIR/VTK/vtk$VTKVER-py$PYVER
wget http://www.vtk.org/files/release/${VTKVER%.*}/VTK-$VTKVER.tar.gztar zxvf VTK-$VTKVER.tar.gz
mkdir VTK-$VTKVER-py$PYVERmkdir -p $DIR/VTKcd VTK-$VTKVER-py$PYVERif [ ${PYVER%%.*} -eq 2 ]; then EXT=; else EXT=m; fi
ccmake3 -DCMAKE_INSTALL_PREFIX:PATH=$VTKDIR \ -DBUILD_SHARED_LIBS:BOOL=ON \ -DVTK_WRAP_PYTHON:BOOL=ON \
-DVTK_PYTHON_VERSION:STRING=${PYVER%%.*} \ -DPYTHON_EXECUTABLE:PATH=$PYDIR/bin/python${PYVER%%.*} \
-DPYTHON_INCLUDE_DIR:PATH=$PYDIR/include/python${PYVER%.*}$EXT \
-DPYTHON_LIBRARY:PATH=$PYDIR/lib/libpython${PYVER%.*}$EXT.so \ -DVTK_USE_GL2PS:BOOL=ON\
-DVTK_LEGACY_SILENT:BOOL=ON\ ../VTK-$VTKVER
In the ccmake3 windows, I press :
- configure key [c] a first time and waiting one minute configuring finished...
- configure key [c] a second time and waiting 30 seconds configuring finished...
- generate key [g]
Thereafter one can run compilation and installation process ( 5 minutes on my computer) :
make -j 8make -j 8 install
To test the VTK python wrapper, one have to add paths to the previously initialized environment variables
PYTHONPATH and LD_LIBRARY_PATH :
export PATH=$PYDIR/bin:/usr/bin:/bin
export PYTHONPATH=$PYDIR/lib/python${PYVER%.*}/site-packages:$VTKDIR/lib/python${PYVER%.*}/site-packages
export LD_LIBRARY_PATH=$VTKDIR/lib:$PYDIR/lib
and run the python code sphere.py (700 bytes) :
wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/sphere.py
$PYDIR/bin/python${PYVER%%.*} sphere.py
If you have errors as
...ERROR: In .../Rendering/OpenGL2/vtkShaderProgram.cxx, line 430vtkShaderProgram (0x1145600): 1: #version 120...
Your graphic driver does not supported shader so you can try to add the option -DVTK_RENDERING_BACKEND:STRING=OpenGL
to cmake3 command :
ccmake3 -DCMAKE_INSTALL_PREFIX:PATH=$VTKDIR \ -DBUILD_SHARED_LIBS:BOOL=ON \ -DVTK_WRAP_PYTHON:BOOL=ON \
-DVTK_PYTHON_VERSION:STRING=${PYVER%%.*} \ -DPYTHON_EXECUTABLE:PATH=$PYDIR/bin/python${PYVER%%.*} \
-DPYTHON_INCLUDE_DIR:PATH=$PYDIR/include/python${PYVER%.*}$EXT \
-DPYTHON_LIBRARY:PATH=$PYDIR/lib/libpython${PYVER%.*}$EXT.so \ -DVTK_LEGACY_SILENT:BOOL=ON\
-DVTK_RENDERING_BACKEND:STRING=OpenGL\ ../VTK-$VTKVERmake -j 8 install
To save environment variables in a file one can do :
FILE=~/setmyPython$PYVER.shecho "export PATH=$PATH" > $FILE
echo "export PYTHONPATH=$PYTHONPATH" >> $FILEecho "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $FILE
echo "export PYTHON=$PYDIR/bin/python${PYVER%.*}" >> $FILEecho "export MPLBACKEND=Qt4Agg" >> FILE
echo "Writing environment variables in $FILE"echo "To load set environment variables do:"echo " source $FILE"
Thereafter one can source the created file to reload them in any terminal
source ~/setmyPython3.6.4.sh
Installing PyQt
We first have to install sip package. The environment variables PATH, PYTHONPATH and LD_LIBRARY_PATH must
be correctly set and PYTHON is either python3 (version 3 of Python) or python2 (version 2 of Python) depending
on previously installed version.
PYTHON=$PYDIR/bin/python${PYVER%.*}SIPVER=4.19.8cd $CDIR
wget https://sourceforge.net/projects/pyqt/files/sip/sip-$SIPVER/sip-$SIPVER.tar.gz
tar zxvf sip-$SIPVER.tar.gzcd sip-$SIPVER/$PYTHON configure.pymake -j 8make install
Then we can install PyQt4 package (PyQt5 is not compatible with Mayavi). For my usage, I don’t need to install
QT designer plugin (must be root for that) so I use the --no-designer-plugin option with configure-ng.py
QT4VER=4.12.1cd $DIRexport PATH=$PATH:/usr/lib64/qt4/bin
wget https://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-$QT4VER/PyQt4_gpl_x11-$QT4VER.tar.gz
tar zxf PyQt4_gpl_x11-$QT4VER.tar.gzcd PyQt4_gpl_x11-$QT4VER
$PYTHON configure-ng.py --confirm-license --no-designer-pluginmake -j 8make install
To quickly test the PyQt4 package, one can run the python code pyqt4_window.py (339 bytes) .
export MPLBACKEND=Qt4Aggwget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/pyqt4_window.py
$PYTHON pyqt4_window.py
In the following we suppose the environment variables PATH, PYTHONPATH, LD_LIBRARY_PATH and MPLBACKEND set as
export PATH=$PYDIR/bin:/usr/bin:/bin
export PYTHONPATH=$PYDIR/lib/python${PYVER%.*}/site-packages:$VTKDIR/lib/python${PYVER%.*}/site-packages
export LD_LIBRARY_PATH=$VTKDIR/lib:$PYDIR/libexport MPLBACKEND=Qt4Agg
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).
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$PYTHON mayavi_boy.py
- When running mayavi_boy.py script, if you have the following warning :
..../site-packages/tvtk/array_handler.py:268: FutureWarning: Conversion of the second argument of issubdtype from ‘complex‘ to ‘np.complexfloating‘ is deprecated. In future, it will be treated as ‘np.complex128 == np.dtype(complex).type‘.
assert not numpy.issubdtype(z.dtype, complex), \
then change the line 268 of file ..../site-packages/tvtk/array_handler.py by
assert not numpy.issubdtype(z.dtype, numpy.complexfloating), \
(Take care to respect identation).
See https://github.com/enthought/mayavi/pull/588/files.
- When saving a mlab figure in pdf format , I have the following error :
Saving as a vector PS/EPS/PDF/TeX file using GL2PS is either not supported
by your version of VTK or you have not configured VTK to work with GL2PS
-- read the documentation for the vtkGL2PSExporter class.