I recently tried pyInstaller and there are some things i don't quite get. i have been trying to create some executables (NOTE: all of them use numpy, scipy, OpenCV, BLAS etc) but i have been failing. There is always something missing. So my question is, can someone explain better to me what are hiddenimports and hooks, and how can i tell pyInstaller the directories of all the dependencies in my code so it can pack the in the final executable.
Thank you.
From the pyinstaller documentation
hiddenimports
A list of modules names (relative or absolute) the module imports in some untrackable way.
Some Python imports are untrackable during static analysis of your program. eg Your code may create the name of a module to import using Python code, and then import that module. In this case, pyinstaller will be unable to work out during its code analysis, what is the name of the module to import. If you know ahead of time, then you can tell pyinstaller to unconditionally include these modules.
Hooks are a way for you to bundle a set of hidden imports and other parameters to do with finding modules. Hooks are named hook-<module>.py
where module is a fully qualified module name. eg hook-xml.dom.py
. If your code does import xml.dom
, then the contents of the hook script are read to include any hidden imports specific to xml.dom
.
If you create your own module and it requires hidden imports, you can create a hook script with the appropriate hidden imports settings and store in the PyInstaller hooks directory. The next time you use PyInstaller to freeze a program which imports your module, it will automatically find your hook file and pull in the required hidden imports without you having to remember each time what the hidden imports are for your module.
The documentation has more information about how all of this works but hopefully this provides some more background information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With