ITK Python pyinstaller issue


(Sshamekhi) #1

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.


(Matt McCormick) #2

Hi @sshamekhi,

There is work in progress for this issue here:

You can subscribe to the issue on GitHub (using the Subscribe button on the right), to receive email updates on its progress.

Thanks,
Matt


(Sshamekhi) #3

Hi,
I will try it,
Thank you so much,


(Francois Budin) #4

You can try to use a hook file with this content:

# 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!


(Francois Budin) #5

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.