Search code examples
pythonpyqtpy2exevtkpyinstaller

Python executable with VTK... pyinstaller, py2exe, cx_freeze etc


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).


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.