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.
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
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
Install 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:
For PyQt version 4, the package qt4-devel must be installed
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
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 dl imageop sunaudiodev To find the necessary bits, look in setup.py in detect_modules() for the module’s name. ...
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
export PATH=$PYDIR/bin:/usr/bin:/bin export PYTHONPATH=$PYDIR/lib/python${PYVER%.*}/site-packages export LD_LIBRARY_PATH=$PYDIR/lib
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 $CDIR VTKVER=8.1.0 VTKDIR=$DIR/VTK/vtk$VTKVER-py$PYVER wget http://www.vtk.org/files/release/${VTKVER%.*}/VTK-$VTKVER.tar.gz tar zxvf VTK-$VTKVER.tar.gz mkdir VTK-$VTKVER-py$PYVER mkdir -p $DIR/VTK cd VTK-$VTKVER-py$PYVER if [ ${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
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) :
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
wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/sphere.py $PYDIR/bin/python${PYVER%%.*} sphere.py
... ERROR: In .../Rendering/OpenGL2/vtkShaderProgram.cxx, line 430 vtkShaderProgram (0x1145600): 1: #version 120 ...
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-$VTKVER make -j 8 install
FILE=~/setmyPython$PYVER.sh echo "export PATH=$PATH" > $FILE echo "export PYTHONPATH=$PYTHONPATH" >> $FILE echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $FILE echo "export PYTHON=$PYDIR/bin/python${PYVER%.*}" >> $FILE echo "export MPLBACKEND=Qt4Agg" >> FILE echo "Writing environment variables in $FILE" echo "To load set environment variables do:" echo " source $FILE"
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.8 cd $CDIR wget https://sourceforge.net/projects/pyqt/files/sip/sip-$SIPVER/sip-$SIPVER.tar.gz tar zxvf sip-$SIPVER.tar.gz cd sip-$SIPVER/ $PYTHON configure.py make -j 8 make install
QT4VER=4.12.1 cd $DIR export 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.gz cd PyQt4_gpl_x11-$QT4VER $PYTHON configure-ng.py --confirm-license --no-designer-plugin make -j 8 make install
export MPLBACKEND=Qt4Agg wget http://www.math.univ-paris13.fr/~cuvelier/docs/Informatique/Python/pyqt4_window.py $PYTHON pyqt4_window.py
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 export MPLBACKEND=Qt4Agg
I choose to install matplotlib package after the installation of PyQt.
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), \
When saving a mlab figure in pdf format , I have the following error: