Question

I've built a gui in python using pyqt which imports VTK. I'm having no luck whatsoever getting py2exe, pyinstaller cx_freeze etc to work with it... I get an error saying something along the lines of the following using pyinstaller:

vtk.__helper.LinkError: No module named vtkFilteringPythonSIP

I have managed to make working executables that don't contain vtk code with pyinstaller so I'm leaning towards that at the moment, but if someone can help me write code which will make this: http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt code work as an executable then I will be eternally grateful, however it is done. I've tried adding the files it complains about to the pyinstaller hooks but still no luck. Is there an old/ development version that has fixed this bug? Can't find any solutions on the information super highway although I have found people in the same boat. I'm using the latest version of Python (X,Y).

Was it helpful?

Solution

If anybody stumbles across this having had the same problem, I managed to get my code working by doing the following:

  • In the pyinstaller hooks folder, rename 'hook-vtkpython.py' to 'hook-vtk.py'

I then got a different error when running the executable generated by pyinstaller about not being able to find a module called QtOpenGL. This was happening inside a file in the vtk folder in site-packages called __helper.py. I simply commented out the last two lines to remove its teeth.

I also changed my code so that rather than importing all of vtk I just imported the bits I needed. Not sure if just the first or both of these steps were necessary to solve the problem I'm afraid, but solve it they/it did. The problem was happening with Python (x,y) 2.7.5.1. Your mileage may vary.

OTHER TIPS

I don't have enough rep to comment, so I just respond. I wanted to add, that still in 2021 this is a viable solution. I tried building a Qt-vtk-UI and struggled several hours to build it. Thanks to Peter Greaves, renaming the hook file did the trick for me.

I am using a virtual conda environment with Python 3.6.12, PyQt5 (5.12.2) and vtk 9.0.1. Running pyinstaller with default installation throws errors like "vtk has no attribute vtk.qt" or "vtkmodules.all has no attribute vtkmodules.all.qt" which is looked up when importing the QVTKRenderWindowInteractor. I tried with the hidden imports like here, but that alone didn't fix it. The combination with renaming the vtk-hook works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top