[vtkusers] VTK with python wrapping

David Gobbi david.gobbi at gmail.com
Thu Jan 11 17:49:04 EST 2018


Hi Normanius,

You will have to turn off the following C++ VTK modules, since they use the
Python C API but don't have the Python version number as part of their
library name:
  FiltersPython
  MPI4Py
  RenderingMatplotlib

This should get you a bit further along.

 - David


On Thu, Jan 11, 2018 at 3:17 PM, normanius <juch at zhaw.ch> wrote:

> Dear all I build VTK 8.1.0 from source with python support enabled.
> Everything works fine as long as I build and install either for python 2.7
> or python 3.5 separately. Here is the build instructions I use for building
> VTK on Mac:
>
> VTK_INSTALL_DIR="/opt/dev/versions/vtk/vtk-8.1.0-qt5-shared"
> mkdir build-python3.5
> cd build-python3.5
> cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release \
>                   -DVTK_WRAP_PYTHON=ON \
>                   -DBUILD_EXAMPLES=OFF \
>                   -DBUILD_SHARED_LIBS=ON \
>                   -DBUILD_TESTING=OFF \
>                   -DCMAKE_INSTALL_PREFIX="$VTK_INSTALL_DIR" \
>                   -DCMAKE_MACOSX_RPATH=ON \
>                   -DCMAKE_INSTALL_RPATH="$VTK_INSTALL_DIR/lib" \
>                   -DVTK_PYTHON_VERSION=3 \
>                   -DPYTHON_EXECUTABLE="/Library/Frameworks/Python.framework/Versions/3.5/bin/python3" \
>                   -DPYTHON_INCLUDE_DIR="/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m/" \
>                   -DPYTHON_LIBRARY="/Library/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib" \
>                   -DVTK_Group_Qt=ON \
>                   -DVTK_QT_VERSION=5 \
>                   -DCMAKE_PREFIX_PATH="$QT_DIR/.."
> ninja
> ninja install
>
> mkdir build-python2.7
> cd build-python2.7
> # Same installation target!
> VTK_INSTALL_DIR="/opt/dev/versions/vtk/vtk-8.1.0-qt5-shared"
> cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release \
>                   -DVTK_WRAP_PYTHON=ON \
>                   -DBUILD_EXAMPLES=OFF \
>                   -DBUILD_SHARED_LIBS=ON \
>                   -DBUILD_TESTING=OFF \
>                   -DCMAKE_INSTALL_PREFIX="$VTK_INSTALL_DIR" \
>                   -DCMAKE_MACOSX_RPATH=ON \
>                   -DCMAKE_INSTALL_RPATH="$VTK_INSTALL_DIR/lib" \
>                   -DVTK_PYTHON_VERSION=2 \
>                   -DPYTHON_EXECUTABLE="/Library/Frameworks/Python.framework/Versions/2.7/bin/python2" \
>                   -DPYTHON_INCLUDE_DIR="/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/" \
>                   -DPYTHON_LIBRARY="/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib" \
>                   -DVTK_Group_Qt=ON \
>                   -DVTK_QT_VERSION=5 \
>                   -DCMAKE_PREFIX_PATH="$QT_DIR/.."
>
> If I use different installation targets
>
> VTK_INSTALL_DIR_PY2
>
> and
>
> VTK_INSTALL_DIR_PY3
>
> , I can import vtk at the following locations without any problems:
>
> cd $VTK_INSTALL_DIR_PY2/lib/python2.7/site-packages; python -c "import vtk"  # No error
> cd $VTK_INSTALL_DIR_PY3/lib/python3.5/site-packages; python -c "import vtk"  # No error
>
> However if I set VTK_INSTALL_DIR_PY2 equal to $VTK_INSTALL_DIR_PY3, I will
> get an error for the version that was installed second. I cannot follow why
> this problem occurs at all, because the installed wrapper binaries (for
> instance libvtkRenderingCorePython27D-8.1.dylib and
> libvtkRenderingCorePython35D-8.1.dylib), are separate from each other.
> And also otool (on Mac) indicates that binaries actually point to the right
> parts. Also, I removed vtk otherwise from the system, so there is not a
> third version that interferes with the installation... Do you have an idea
> where the problem comes from? The error message by the way looks like this
> for me:
>
> import vtk
> ---------------------------------------------------------------------------
> ImportError                               Traceback (most recent call last)
> /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/python3.5/site-packages/vtk/vtkFiltersPython.py in <module>()
>       4     # use relative import for installed modules
> ----> 5     from .vtkFiltersPythonPython import *
>       6 except ImportError:
>
> ImportError: dlopen(/opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/python3.5/site-packages/vtk/vtkFiltersPythonPython.so, 2): Symbol not found: __Py_ZeroStruct
>   Referenced from: /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/libvtkWrappingPython27Core-8.1.1.dylib
>   Expected in: flat namespace
>  in /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/libvtkWrappingPython27Core-8.1.1.dylib
>
> During handling of the above exception, another exception occurred:
>
> ImportError                               Traceback (most recent call last)
> <ipython-input-1-b7e11aadda62> in <module>()
> ----> 1 import vtk
>
> /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/python3.5/site-packages/vtk/__init__.py in <module>()
>      48 from .vtkFiltersPoints import *
>      49 from .vtkFiltersProgrammable import *
> ---> 50 from .vtkFiltersPython import *
>      51 from .vtkFiltersSMP import *
>      52 from .vtkFiltersSelection import *
>
> /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/python3.5/site-packages/vtk/vtkFiltersPython.py in <module>()
>       7     # during build and testing, the modules will be elsewhere,
>       8     # e.g. in lib directory or Release/Debug config directories
> ----> 9     from vtkFiltersPythonPython import *
>
> ImportError: No module named 'vtkFiltersPythonPython'
>
> Many thanks for any hints on this!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180111/476302a8/attachment.html>


More information about the vtkusers mailing list