Raspberry PI5 + Python + VTK

I’m not able to find a VTK Python package for Raspberry Pi 5 (Python 3.11.2).
How to install it ?
There is some pre-made package and instructions to install it ?

PS:
I’ve tried to make VTK from the vtk repository in a virtual env to not touch the original python installation:

python3 -m venv /home/<user>/develop/venv
cd /home/<user>/develop/venv/bin
./pip3 install numpy
./pip3 install PySide6
sudo apt install -y build-essential mesa-common-dev mesa-utils freeglut3-dev ninja-build git cmake
cd /home/<user>
mkdir develop
cd develop
git clone --recursive https://gitlab.kitware.com/vtk/vtk.git
cd ..
mkdir build
cd build
cmake -GNinja -DVTK_WHEEL_BUILD=ON -DVTK_WRAP_PYTHON=ON /data/vtk
ninja
cp -R /home/<user>/develop/build/lib /home/<user>/develop/venv/lib/python3.11/site-packages
cp -R /home/<user>/develop/build/lib /home/<user>/develop/venv/lib/python3.11/

Something works but python program crashes, for Segmentation fault, after some rotations of OpenGL scene and I’ve got a lot of error logs.

A little piece of logs:

024-06-05 09:29:13.869 (   8.856s) [    7FFF94FC4700]     vtkOpenGLState.cxx:943   WARN| Error glViewport1 OpenGL errors detected
  0 : (1280) Invalid enum

 with stack trace of
0x7fff91025bd4 : ??? [(???) ???:-1]
0x7fff91020a40 : vtksys::SystemInformation::GetProgramStack[abi:cxx11](int, int) [(libvtksys-9.3.so.1) ???:-1]
0x7fff89feef60 : ??? [(???) ???:-1]
0x7fff89ff2aac : vtkOpenGLState::vtkglViewport(int, int, int, int) [(libvtkRenderingOpenGL2-9.3.so.1) ???:-1]
0x7fff89fbde4c : vtkOpenGLRenderWindow::Frame() [(libvtkRenderingOpenGL2-9.3.so.1) ???:-1]
0x7fff8a0ae4e0 : vtkXOpenGLRenderWindow::Frame() [(libvtkRenderingOpenGL2-9.3.so.1) ???:-1]
0x7fff8cd38624 : vtkRenderWindow::CopyResultFrame() [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff8cd36e6c : vtkRenderWindow::Render() [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff89fc3214 : vtkOpenGLRenderWindow::Render() [(libvtkRenderingOpenGL2-9.3.so.1) ???:-1]
0x7fff8a0b3f18 : vtkXOpenGLRenderWindow::Render() [(libvtkRenderingOpenGL2-9.3.so.1) ???:-1]
0x7fff8cd41f3c : vtkRenderWindowInteractor::Render() [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff8cde8a0c : vtkInteractorStyle::StopState() [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff8cde9054 : vtkInteractorStyle::EndRotate() [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff8ba8786c : vtkInteractorStyleJoystickCamera::OnLeftButtonUp() [(libvtkInteractionStyle-9.3.so.1) ???:-1]
0x7fff8cdeb184 : vtkInteractorStyle::ProcessEvents(vtkObject*, unsigned long, void*, void*) [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff92ff7ca0 : vtkCallbackCommand::Execute(vtkObject*, unsigned long, void*) [(libvtkCommonCore-9.3.so.1) ???:-1]
0x7fff931184e4 : ??? [(???) ???:-1]
0x7fff93118c68 : vtkObject::InvokeEvent(unsigned long, void*) [(libvtkCommonCore-9.3.so.1) ???:-1]
0x7fff89636cbc : vtkXRenderWindowInteractor::DispatchEvent(_XEvent*) [(libvtkRenderingUI-9.3.so.1) ???:-1]
0x7fff896353d0 : vtkXRenderWindowInteractor::ProcessEvents() [(libvtkRenderingUI-9.3.so.1) ???:-1]
0x7fff89635970 : vtkXRenderWindowInteractor::StartEventLoop() [(libvtkRenderingUI-9.3.so.1) ???:-1]
0x7fff8cd42108 : vtkRenderWindowInteractor::Start() [(libvtkRenderingCore-9.3.so.1) ???:-1]
0x7fff8d1343e4 : ??? [(???) ???:-1]
0x4c9d8c : ??? [(???) ???:-1]
0x494548 : _PyObject_MakeTpCall [(python3) ???:-1]
0x4aa23c : _PyEval_EvalFrameDefault [(python3) ???:-1]
0x4a0b60 : PyEval_EvalCode [(python3) ???:-1]
0x5fafa8 : ??? [(???) ???:-1]
0x5f7bd0 : ??? [(???) ???:-1]
0x608760 : ??? [(???) ???:-1]
0x608308 : _PyRun_SimpleFileObject [(python3) ???:-1]
0x608070 : _PyRun_AnyFileObject [(python3) ???:-1]
0x60631c : Py_RunMain [(python3) ???:-1]
0x5d0154 : Py_BytesMain [(python3) ???:-1]
0x7fff94cb7780 : ??? [(???) ???:-1]
0x7fff94cb7858 : __libc_start_main [(libc.so.6) ???:-1]
0x5cfff0 : _start [(python3) ???:-1]

Did you also post this here?
https://forums.raspberrypi.com/viewtopic.php?t=371878

David Gobbi has some information for RPi4 here.
Here is a Kitware blog entry on VTK and RPi.

Did you also post this here?
Yes, I’ve tried to collect suggestions also in Raspberry forum.

I will read carefully any suggested link.

At the moment RPI 5 is running ninja to try a new cmake configuration (Will take a looong time to finish).
Currently this is my build environment:

#== BEG: UPDATE OS =====================================================================================================
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt update
$ sudo apt upgrade
$ sudo apt autoremove
#== END: UPDATE OS =====================================================================================================


#== BEG: INSTALL REQUIREMENTS ==========================================================================================
$ sudo apt install -y build-essential mesa-common-dev mesa-utils freeglut3-dev ninja-build git cmake cmake-curses-gui
  Reading package lists... Done
  Building dependency tree... Done
  Reading state information... Done
  build-essential is already the newest version (12.9).
  mesa-common-dev is already the newest version (23.2.1-1~bpo12+rpt3).
  mesa-utils is already the newest version (8.5.0-1).
  freeglut3-dev is already the newest version (3.4.0-1).
  ninja-build is already the newest version (1.11.1-1).
  git is already the newest version (1:2.39.2-1.1).
  cmake is already the newest version (3.25.1-1).
  cmake-curses-gui is already the newest version (3.25.1-1).
  0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
#== END: INSTALL REQUIREMENTS ==========================================================================================


#== BEG: CHECK SYSTEM ==================================================================================================
$ uname -a
  Linux pi 6.6.31+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux

$ cat /etc/os-release
  PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
  NAME="Debian GNU/Linux"
  VERSION_ID="12"
  VERSION="12 (bookworm)"
  VERSION_CODENAME=bookworm
  ID=debian
  HOME_URL="https://www.debian.org/"
  SUPPORT_URL="https://www.debian.org/support"
  BUG_REPORT_URL="https://bugs.debian.org/"

$ sudo apt install neofetch
$ neofetch --stdout
  OS: Debian GNU/Linux 12 (bookworm) aarch64 
  Host: Raspberry Pi 5 Model B Rev 1.0 
  Kernel: 6.6.31+rpt-rpi-2712 
  Uptime: 2 hours, 56 mins 
  Packages: 1708 (dpkg) 
  Shell: bash 5.2.15 
  DE: LXDE-pi-wayfire 
  WM: wayfire 
  Theme: PiXflat [GTK3] 
  Icons: PiXflat [GTK3] 
  Terminal: lxterminal 
  Terminal Font: Monospace 10 
  CPU: (4) @ 2.400GHz 
  Memory: 1270MiB / 8052MiB 

$ echo $XDG_SESSION_TYPE
  wayland

$ glxinfo -B
  name of display: :0
  display: :0  screen: 0
  direct rendering: Yes
  Extended renderer info (GLX_MESA_query_renderer):
      Vendor: Broadcom (0x14e4)
      Device: V3D 7.1 (0xffffffff)
      Version: 23.2.1
      Accelerated: yes
      Video memory: 8052MB
      Unified memory: yes
      Preferred profile: core (0x1)
      Max core profile version: 3.1
      Max compat profile version: 3.1
      Max GLES1 profile version: 1.1
      Max GLES[23] profile version: 3.1
  OpenGL vendor string: Broadcom
  OpenGL renderer string: V3D 7.1
  OpenGL core profile version string: 3.1 Mesa 23.2.1-1~bpo12+rpt3
  OpenGL core profile shading language version string: 1.40
  OpenGL core profile context flags: (none)

  OpenGL version string: 3.1 Mesa 23.2.1-1~bpo12+rpt3
  OpenGL shading language version string: 1.40
  OpenGL context flags: (none)

  OpenGL ES profile version string: OpenGL ES 3.1 Mesa 23.2.1-1~bpo12+rpt3
  OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
#== END: CHECK SYSTEM ==================================================================================================


#== BEG: CREATE A PYTHON VIRTUAL ENV ===================================================================================
$ python3 -m venv /home/<user>/develop/venv
$ cd /home/<user>/develop/venv/bin
$ ./pip3 install numpy
$ ./pip3 install wheel
$ ./pip3 install PySide6

#== END: CREATE A PYTHON VIRTUAL ENV ===================================================================================


#== BEG: CLONE VTK REPOSITORY===========================================================================================
$ cd \home\<user>
$ git clone --recursive https://gitlab.kitware.com/vtk/vtk.git
#== END: CLONE VTK REPOSITORY===========================================================================================


#== BEG: MAKE VTK FOR PYTHON + WHEEL====================================================================================
$ mkdir vtk-build-001
$ cd vtk-build-001

$ cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DVTK_OPENGL_USE_GLES=ON -DVTK_MODULE_ENABLE_VTK_RenderingLICOpenGL2:STRING=DONT_WANT -DVTK_WRAP_PYTHON=ON -DVTK_WHEEL_BUILD=ON ../vtk
  ...<cmake log>...

$ ninja
  ...<ninja log>...

$ /home/<user>/venv/bin/python3 setup.py bdist_wheel
  ...<setup log>...
#== END: MAKE VTK FOR PYTHON + WHEEL====================================================================================


#== BEG: INSTALL VTK WHEEL =============================================================================================
$ /home/<user>/venv/bin/pip3 install dist/vtk-9.3.20240606.dev0-cp311-cp311-linux_aarch64.whl
  ...<vtk wheel install log>...   
#== END: INSTALL VTK WHEEL =============================================================================================

Not only will it take a long time to finish, it’ll thrash your SD card pretty badly - you will likely lose some life on that thing. There is a comment I made in the first post here about using toolchain files. These allow you to do the build on your computer, which will be a LOT faster, and won’t thrash your SD card.