Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'vtk' #552

Open
DRLing2021 opened this issue Mar 4, 2023 · 3 comments
Open

ModuleNotFoundError: No module named 'vtk' #552

DRLing2021 opened this issue Mar 4, 2023 · 3 comments

Comments

@DRLing2021
Copy link

DRLing2021 commented Mar 4, 2023

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

@DRLing2021 DRLing2021 added the state:triage We're still figuring out how severe this issue is label Mar 4, 2023
@DRLing2021
Copy link
Author

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.

@rokm
Copy link
Member

rokm commented Mar 5, 2023

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?

@rokm rokm removed the state:triage We're still figuring out how severe this issue is label Mar 5, 2023
@DRLing2021
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants