PyInstaller什么是hiddenimports和hooks? [英] PyInstaller what are hiddenimports and hooks?

查看:1391
本文介绍了PyInstaller什么是hiddenimports和hooks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近尝试了pyInstaller,有些事情我不太了解.我一直在尝试创建一些可执行文件(注意:它们全部使用numpy,scipy,OpenCV,BLAS等),但我一直失败.总是缺少一些东西.所以我的问题是,有人可以更好地向我解释什么是隐藏的导入和挂钩,我如何告诉pyInstaller我代码中所有依赖项的目录,以便可以将它们打包在最终的可执行文件中.

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.

谢谢.

推荐答案

来自 pyinstaller文档

隐藏的进口

hiddenimports

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

在对程序进行静态分析期间,某些Python导入无法跟踪.例如,您的代码可以创建要使用Python代码导入的模块的名称,然后导入该模块.在这种情况下,pyinstaller将无法在其代码分析期间计算出要导入的模块的名称.如果您提前知道,则可以告诉pyinstaller无条件包括这些模块.

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.

钩子是您捆绑一组隐藏的导入和其他与查找模块有关的参数的方法.挂钩的名称为hook-<module>.py,其中module是完全限定的模块名称.例如hook-xml.dom.py.如果您的代码执行import xml.dom,则将读取钩子脚本的内容,以包括任何特定于xml.dom的隐藏导入.

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.

如果您创建自己的模块并且需要隐藏的导入,则可以使用适当的隐藏的导入设置创建一个钩子脚本,并将其存储在PyInstaller钩子目录中.下次使用PyInstaller冻结导入模块的程序时,它将自动找到您的钩子文件并提取所需的隐藏导入,而您不必每次都记住模块的隐藏导入是什么.

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.

这篇关于PyInstaller什么是hiddenimports和hooks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆