pyinstaller-hooks-contrib
pyinstaller-hooks-contrib copied to clipboard
ModuleNotFoundError: No module named 'vtk'
Hello,
After running pyinstaller against a python script with vtk import successfully, we tried the exe file with error:
“ModuleNotFoundError: No module named 'vtk'”
A minimal example file:
The script in error is in fact a caller which calls the pyd module that contains the compiled functions by cython. So there is no real action except the __name__ == "__main__". All the rest are imports, see following;
import sys
import sys,os
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtWidgets import QFileDialog
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor <== report error when run the EXE
from vedo import Plotter, Points,Arrow #,Mesh
import Load_Data_Proc as Proc_Load <== our pyd module
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = Proc_Load.Plot_App()
app.aboutToQuit.connect(app.deleteLater) ## fix spyder run Qt app one time
window.show()
sys.exit(app.exec_())
PyInstaller command:
pyinstaller Caller_proc.spec --clean
Error:
Traceback (most recent call last):
File "Caller_proc.py", line 13, in <module>
ModuleNotFoundError: No module named 'vtk'
[2448] Failed to execute script 'Caller_proc' due to unhandled exception!
Expected behavior Run exe well
Screenshots NA
Desktop (please complete the following information):
- OS: Windows 10
- Python Version: 3.9.7
- Version of
pyinstaller-hooks-contrib: 2023.0 [ got from folder name, 2023.0.dist-info, not sure how to check it by command] - Version of PyInstaller 5.8.0
** Addtional info ** Before running pyinstaller we changed Caller_proc.spec by adding:
hiddenimports=["vtkmodules.vtkCommonMath",
"vtkmodules.vtkCommonTransforms",
"vtkmodules.vtkCommonExecutionModel",
"vtkmodules.vtkIOCore",
"vtkmodules.vtkRenderingCore",
"vtkmodules.vtkFiltersCore",
"vtkmodules.vtkCommonMisc",
"vtkmodules.vtkRenderingVolumeOpenGL2",
"vtkmodules.vtkImagingMath",],
which does not help at all
Thank you for your help in advance Regards DR,Ling
ps, we did not find any of hook-vtk-?????.py or similar file names under pyinstaller/hook folder. So we changed the spec file directly.
Hmm, looks like vtk is not really a package but a top-level module that is trying to emulate a package by importing and mapping all symbols from vtkmodules.*. So for example vtk.qt is really vtkmodules.qt. This likely confuses our analysis and we fail to collect the relevant modules.
For the minimized version of your entry-point script,
import sys
import sys,os
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtWidgets import QFileDialog
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor # <== report error when run the EXE
# from vedo import Plotter, Points,Arrow #,Mesh
#import Load_Data_Proc as Proc_Load # <== our pyd module
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
print("Hello world!")
#window = Proc_Load.Plot_App()
#app.aboutToQuit.connect(app.deleteLater) ## fix spyder run Qt app one time
#window.show()
#sys.exit(app.exec_())
it seems that adding vtk and vtkmodules.qt.QVTKRenderWindowInteractor to hidden imports is enough to get it past the missing module errors raised by from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor.
Can you try adding vtk and vtkmodules.qt.QVTKRenderWindowInteractor to hiddenimports in your spec file?
Hi Rokm,
We changed the import line to import vtkmoudules.xxx, then verything is fine now. Thank you very much for your quick response. Is there any way to fix it by pyinstaller natively?
Regards, DR, Ling