简体   繁体   English

如何将多个文件夹层次结构中的所有 python 文件导入单个 pyinstaller 可执行文件?

[英]How can I import all my python files in multiple folder hierarchy into a single pyinstaller executable?

I am developing a PyQT based Windows Application.我正在开发基于 PyQT 的 Windows 应用程序。 I have lot of folders with many python files.我有很多文件夹,其中包含许多 python 文件。 But when I try to create an executable with the pyinstaller python package,the dependencies of the files in the other folders could not be resolved.但是,当我尝试使用 pyinstaller python package 创建可执行文件时,无法解决其他文件夹中文件的依赖关系。 For Simplicity, this is my folder structure为了简单起见,这是我的文件夹结构

gui
    -gui.py
    -main.py
libs
    -testlibs.py
utility
    -folderstructure.py

I have used the command pyinstaller main.py --onefile The problem is gui.py imports utility.folderstructure which couldnot be resolved after the exe is generated.我使用了命令pyinstaller main.py --onefile问题是gui.py imports utility.folderstructure 生成exe后无法解决。

The exe is throwing execption that utility cannot be found.该 exe 正在抛出无法找到该实用程序的 execption。

I have added addition hook directory option.我添加了附加挂钩目录选项。 In that I have added a file named hook-gui.py with content hiddenimports=[".utility.folderstructure.*"] Now my folderstructure is其中我添加了一个名为 hook-gui.py 的文件,其内容为 hiddenimports=[".utility.folderstructure.*"] 现在我的文件夹结构是

gui
    -gui.py
    -main.py
    -hook-gui.py
libs
    -testlibs.py
utility
    -folderstructure.py

But while running the command pyinstaller ----additional-hooks-dir=.但是在运行命令pyinstaller ----additional-hooks-dir=。 main.py --onefile main.py --onefile

INFO: Loading module hook hook-gui.py ... WARNING: Hidden import .utility.folderstructure.* not found.信息:加载模块挂钩hook-gui.py ... 警告:未找到隐藏的导入.utility.folderstructure.* This particular error pops up.弹出此特定错误。

Could you tell where I am wrong?你能告诉我哪里错了吗?

Normally I would use a layout similar to:通常我会使用类似于以下的布局:

-main.py
-gui
    -init.py
    -gui.py
    -hook-gui.py
-libs
    -init.py
    -testlibs.py
-utility
    -init.py
    -folderstructure.py

Pyinstaller has always found the modules for me in this style layout. Pyinstaller 总是以这种风格的布局为我找到模块。

You're just going to have to adjust some imports.你只需要调整一些进口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM