I am compiling and installing VTK (from source) with Python wrappers using my install_VTK.sh
file (see below).
(I require VTK in order to use mayavi.
Currently conda does not have VTK v8.1.0 and a version of mayavi compatible with Python 3.)
Using install_VTK.sh
VTK successfully complies and installs.
Running the Python wrapper created by VTK:
>>> vtkpython -c "import vtk"
is successful.
However using the standard python:
>>> python -c "import vtk"
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
is not.
This means that in order to install mayavi successfully I temporarily create an alias python -> vtkpython
before
>>> pip install mayavi
and then restore the original python -> python3.5
.
I believe python -c "import vtk"
fails because the python library libpython3.5m.dylib
is not linked in the VTK wrapper files unlike in vtkpython:
>>> otool -L libvtkCommonCorePython35D-8.1.dylib
libvtkCommonCorePython35D-8.1.dylib:
@rpath/libvtkCommonCorePython35D-8.1.1.dylib
@rpath/libvtkWrappingPython35Core-8.1.1.dylib
@rpath/libvtkCommonCore-8.1.1.dylib
@rpath/libvtksys-8.1.1.dylib
/usr/lib/libc++.1.dylib
/usr/lib/libSystem.B.dylib
>>> otool -L vtkpython
vtkpython:
@rpath/libpython3.5m.dylib
@rpath/libvtkWrappingPython35Core-8.1.1.dylib
@rpath/libvtkCommonCore-8.1.1.dylib
@rpath/libvtksys-8.1.1.dylib
/usr/lib/libutil.dylib
/usr/lib/libc++.1.dylib
/usr/lib/libSystem.B.dylib
I believe (please correct me) that this is a result of this change (to fix this bug) to allow VTK to use compatible Python versions that are installed in different locations from what was used in the initial build.
I would like to know if it is possible to force the inclusion of @rpath/libpython3.5m.dylib
when calling cmake
.
The common suggestion is
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH":<path>/.miniconda3/envs/testVTK/lib"
but apparently this is considered bad practice and fails anyway:
vtkpython -c "import vtk"
Traceback (most recent call last):
File "<path>/.miniconda3/envs/testVTK/lib/python3.5/site-packages/vtk/vtkRenderingFreeType.py", line 5, in <module>
from .vtkRenderingFreeTypePython import *
ImportError: dlopen(<path>/.miniconda3/envs/testVTK/lib/python3.5/site-packages/vtk/vtkRenderingFreeTypePython.so, 2): Symbol not found: _sqlite3_intarray_bind
Referenced from: /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
Expected in: <path>/.miniconda3/envs/testVTK/lib/libsqlite3.dylib
in /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<path>/.miniconda3/envs/light-3.5/lib/python3.5/site-packages/vtk/__init__.py", line 26, in <module>
from .vtkRenderingFreeType import *
File "<path>/.miniconda3/envs/light-3.5/lib/python3.5/site-packages/vtk/vtkRenderingFreeType.py", line 9, in <module>
from vtkRenderingFreeTypePython import *
ImportError: dlopen(<path>/downloads/VTK-8.1.0/vtkBuild_3.5/lib/vtkRenderingFreeTypePython.so, 2): Symbol not found: _sqlite3_intarray_bind
Referenced from: /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
Expected in: <path>/.miniconda3/envs/light-3.5/lib/libsqlite3.dylib
in /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
Strangely it also looks back to the build dir:
ImportError: dlopen(<path>/downloads/VTK-8.1.0/vtkBuild_3.5/lib/vtkRenderingFreeTypePython.so, 2): ...
Install File: install_VTK.sh
This is the file I created to build and install VTK
# -- input data --
# The directory path of the extracted download of VTK
VTK_DIR=VTK-8.1.0
PY_VER=3.5
MAIN_PATH=/path/to/python/environment/.miniconda3/envs/testVTK
PY_LIB=libpython${PY_VER}m.dylib
PY_INC=python${PY_VER}m
QMAKE_PATH=${MAIN_PATH}/bin/qmake
CMAKE_PATH=${MAIN_PATH}/bin/cmake
# -- move into dir --
cd ${VTK_DIR}
BUILD_DIR=vtkBuild_${PY_VER}
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
CMAKE_OPTIONS="
-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PATH} \
-DCMAKE_INSTALL_PREFIX:PATH=${MAIN_PATH} \
-DCMAKE_MACOSX_RPATH:BOOL=ON \
-DCMAKE_INSTALL_RPATH:PATH=${MAIN_PATH}/lib \
"
# specify the installation of Python
# https://cmake.org/cmake/help/v3.10/module/FindPythonLibs.html
PYTHON_OPTIONS="
-DVTK_PYTHON_VERSION:STRING=${PY_VER} \
-DPYTHON_EXECUTABLE:PATH=${MAIN_PATH}/bin/python${PY_VER} \
-DPYTHON_LIBRARY:PATH=${MAIN_PATH}/lib/${PY_LIB} \
-DPYTHON_LIBRARIES:PATH=${MAIN_PATH}/lib/${PY_LIB} \
-DPYTHON_INCLUDE_DIR:PATH=${MAIN_PATH}/include/${PY_INC} \
-DPYTHON_INCLUDE_DIRS:PATH=${MAIN_PATH}/include/${PY_INC} \
-DVTK_INSTALL_PYTHON_MODULE_DIR:PATH=${MAIN_PATH}/lib/python${PY_VER}/site-packages \
"
# deprecated
# PYTHON_INCLUDE_PATH
# PYTHON_DEBUG_LIBRARIES
# -- additional options --
CC=cc
CXX=c++
ADDITIONAL_OPTIONS="
-DCMAKE_C_COMPILER=${CC} \
-DCMAKE_CXX_COMPILER=${CXX} \
-DVTK_REQUIRED_OBJCXX_FLAGS:STRING='' \
-DVTK_USE_CARBON:BOOL=OFF \
-DVTK_USE_COCOA:BOOL=ON \
-DVTK_USE_X:BOOL=OFF \
-DVTK_USE_TK:BOOL=OFF \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DBUILD_DOCUMENTATION:BOOL=OFF \
-DVTK_HAS_FEENABLEEXCEPT:BOOL=OFF \
-DBUILD_TESTING:BOOL=OFF \
-DBUILD_EXAMPLES:BOOL=OFF \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DVTK_WRAP_PYTHON:BOOL=ON \
-DModule_vtkRenderingMatplotlib:BOOL=ON \
"
# ---------------------------------------------------------------------------
HDF5_OPTIONS="
-DVTK_USE_SYSTEM_HDF5:BOOL=ON \
"
MPI_OPTIONS="
-DModule_vtkParallelMPI:BOOL=ON \
"
#mayavi needs version 4
QT_OPTIONS="
-DVTK_QT_VERSION:STRING=4 \
-DQT_QMAKE_EXECUTABLE:PATH=${QMAKE_PATH} \
-DVTK_Group_Qt:BOOL=ON \
"
EXTENSION_OPTIONS=$HDF5_OPTIONS$MPI_OPTIONS$QT_OPTIONS
# ---------------------------------------------------------------------------
OPTIONS=$CMAKE_OPTIONS$PYTHON_OPTIONS$ADDITIONAL_OPTIONS$EXTENSION_OPTIONS
cmake $OPTIONS ..
# -- build --
# make with max number of logical cores
make -j $(sysctl -n hw.logicalcpu_max)
make install
System
- Mac 10.13.2
- VTK 8.1.0
- cmake 3.10.0
- Python 3.5 (Miniconda)
- Additional python versions are also on the system (2.7, 3.6)