PyInstaller, what are hidden and intercepts hooks?

I tried pyInstaller recently, and there are some things that I don’t quite understand. I am trying to create some executables (NOTE: they all use numpy, scipy, OpenCV, BLAS, etc.), but I have failed. There is always something missing. So my question is: can someone better explain to me what is hidden and intercepts hooks, and how can I tell pyInstaller the directories of all the dependencies in my code so that it can be packed into the final executable.

Thanks.

+4
source share
1 answer

From pyinstaller documentation

hiddenimports

A list of modules names (relative or absolute) the module imports in some untrackable way. 

Some imported Python are not available when statically analyzing your program. for example, your code could create a module name to import using Python code, and then import that module. In this case, pyinstaller will not be able to work during code analysis, what is the name of the module to import. If you know in advance, then you can say that pyinstaller unconditionally includes these modules.

Hooks are a way for you to link a set of hidden imports and other parameters related to finding modules. The hooks are called hook-<module>.py , where the module is the full name of the module. e.g. hook-xml.dom.py . If your code does import xml.dom , then the contents of the script hook are read to include any hidden imports specific to xml.dom .

If you create your own module and require hidden imports, you can create a hook script with the corresponding hidden import parameters and save it in the PyInstaller hook directory. The next time you use PyInstaller to freeze a program that imports your module, it will automatically find your hook file and pull out the necessary hidden import, without worrying about what hidden imports are for your module.

The documentation has more information on how this all works, but hopefully this provides additional background information.

+10
source

All Articles