Dear all
I am using ITKPython,
My codes are working well in PyCharm with *.py format but after making a standalone *.exe file via PyInstaller some errors occure as follow:
Traceback (most recent call last):
File “RSG_V_0.py”, line 27, in <module>
File “site-packages\itkExtras.py”, line 449, in imread
File “site-packages\itkLazy.py”, line 40, in getattribute
AttributeError: ‘LazyITKModule’ object has no attribute ‘ImageFileReader’
[29316] Failed to execute script RSG_V_0
Would you please show me the way to solve these kind of problems.
I attaches a simple .py,
By the way, already I test my PyInstaller with a simple print.py.
# This pyinstaller hook file does not support ITK with `WrapITK.pth`.
from PyInstaller.utils.hooks import collect_data_files
hiddenimports = ['new']
# If ITK is pip installed, gets all the files.
itk_datas = collect_data_files('itk', include_py_files=True)
datas = [x for x in itk_datas if '__pycache__' not in x[0]]
Save the code above in a file called hook-itk.py and add --additional-hooks-dir= to the command line calling pyinstaller, with the name of the folder in which you saved hook-itk.py.
If this works for you, I will ask pyinstaller if they can ship this hook file directly in their project.
Thanks!
I created a PR on the pyinstaller project to facilitate using ITK with pyinstaller. I also update my previous answer to improve the hook file that can be used with pyinstaller.