Python VTK and pyInstaller

Hi all,

I am trying to make a portable python vtk reader with pyInstaller. All tested computers have the same OS (windows 7 SP1) but on most of them it doesn’t work.

Here is a test script named “VTK-TEST.py” (a simple vtk window containing a single slider):

#!/usr/bin/env python
import vtk
print(“starting…”)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(600,600)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
sliderRepresent=vtk.vtkSliderRepresentation2D()
sliderRepresent.SetMinimumValue(0.0)
sliderRepresent.SetMaximumValue(1.0)
sliderRepresent.GetPoint1Coordinate().SetCoordinateSystemToDisplay()
sliderRepresent.GetPoint1Coordinate().SetValue(40,70)
sliderRepresent.GetPoint2Coordinate().SetCoordinateSystemToDisplay()
sliderRepresent.GetPoint2Coordinate().SetValue(440,470)
sliderWidget=vtk.vtkSliderWidget()
sliderWidget.SetInteractor(iren)
sliderWidget.SetRepresentation(sliderRepresent)
sliderWidget.SetAnimationModeToAnimate()
sliderWidget.EnabledOn()
iren.Initialize()
renWin.Render()
iren.Start()

Using the following command to make a pyInstaller distribution:

pyInstaller VTK-TEST.py

it produces a folder containing all kind of vtk and python related files and one .exe executable.
Putting the distribution on an USB key, it works on some computers but not others (all with same OS) and I am trying to understand why.

When the produced distribution doesn’t work, launching the .exe results in the following error:

ModuleNotFoundError: no module named ‘vtkCommonKitPython’

(despite the fact that a file named vtkCommonKitPython.pyd is included in the distribution)

I tried edditing the .spec file line: hiddenimports=[‘vtk’], to be sure all vtk dependencies are exported, but using the dist built by the following command, it still doesn’t change anything.

pyInstaller VTK-TEST.spec

I’ve tried doing the same for other simple scripts and tkinter scripts, those distributions work on all our computers as long as vtk is not involved.
I am guessing vtk distributions work or not depending on softwares allready installed on the computer, but I cannot find a common denominator. I would like the distribution to work without having to install anything as much as possible.

I suppose I am missing some tags in the .spec file that would make the vtk distribution work, I ll be grateful if you can help me.

Thanks,

edit I shall specify that I use python 3.7, vtk 8.1.2 and pyInstaller 3.4

After I packaged it with py2app, I also encountered the same error. Can you solve it?

Sorry, I haven’t found a solution so far :confused:

Hello,

Did you find a solution ?

I was able to fix the problem on one computer by updating the windows 7 with update KB2999226. I had to stop the work on this and had no time to try and check if it would have solved the problem with the other computers too. Hopefully, it does.

For me the following works for vtk9:

in the pyinstaller .spec file include the following hidden imports:

hiddenimports=[‘vtkmodules’,‘vtkmodules.all’,‘vtkmodules.qt.QVTKRenderWindowInteractor’,‘vtkmodules.util’,‘vtkmodules.util.numpy_support’,‘vtkmodules.numpy_interface’, ‘vtkmodules.numpy_interface.dataset_adapter’],

Maybe I am a bit late, but for packaging and distribution I use Nuitka, which serves the same purpose, but will convert all your Python code into C code when creating a standalone. There is an unofficial plugin to make VTK compatible with it, it needs to be done with their hinted compilation utility.