InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.43k stars 665 forks source link

Enable Python import analysis for bundlers like pyinstaller, py2app, py2exe #214

Closed thewtex closed 5 years ago

thewtex commented 5 years ago

Python tools to bundle applications and generate installers analyze Python import's to determined what should be included in the package. Some examples include pyinstaller, py2app, py2exe.

To enable these apps to work with the ITK Python package, we need to make some changes to itkBase.py, e.g.

fbudin69500 commented 5 years ago

pyinstaller can be used with ITK if a hook is provided. The hook file should be named hook-itk.py and its content should be:

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]]
fbudin69500 commented 5 years ago

A PR for pyinstaller was opened

fbudin69500 commented 5 years ago

In the meantime, before the PR is merged in pyinstaller (See link above), one can use the hook file above and add the following file to their command line when calling pyinstaller: --additional-hooks-dir

fbudin69500 commented 5 years ago

Closing this issue as there is no problem in ITK to use PyInstaller (see comments and links above).