What is the best way to use Python VTK?

VTK consists of around 120 different modules. When you “import vtk”, it imports all of them and puts their contents into the vtk module for convenience. However, with “from vtkmodules.vtkSomething import something”, you import only the modules that your program needs. This allows your program to start up faster, since fewer modules are loaded.

For most uses of VTK, the difference in start-up speed is not important, so you should use whichever method you prefer. For example, if write a GUI application, then an extra second or two of startup time doesn’t matter. But if you write a utility program that just does some VTK processing and then saves the result, and if the processing itself only takes a fraction of a second, then a startup time of one or two seconds is a performance killer.

3 Likes