简体   繁体   English

如何使用 pyinstaller 将多个 .py 文件构建为单个可执行文件?

[英]How to build multiple .py files into a single executable file using pyinstaller?

I have made a small PyQt application containing 5-6 .py files.我制作了一个包含 5-6 个 .py 文件的小型 PyQt 应用程序。 Now I want to build and compile them into a single main file, meaning it has to operate from one main window exe.现在我想将它们构建并编译成一个主文件,这意味着它必须从一个主窗口 exe 中运行。

My .py files are connected with each other successfully.我的 .py 文件已成功相互连接。 I have used pyinstaller to make the executable file, but the problem is I built each .py file into its own .exe file.我已经使用 pyinstaller 来制作可执行文件,但问题是我将每个 .py 文件构建到了自己的 .exe 文件中。 But I want to make a single .exe file through which all the .py files can be used.但我想制作一个 .exe 文件,通过它可以使用所有 .py 文件。

How to build all .py files into a single .exe file?如何将所有 .py 文件构建为单个 .exe 文件?

Suppose you had a file called create.py like假设您有一个名为create.py的文件,例如

def square (num)
    return num ** 2 

Another file in the same directory called input.py同一目录中的另一个文件名为input.py

from . import create
def take_input():
    x = input("Enter Input")
    return create.square(x)

And finally your main.py最后你的main.py

from . import input
if __name__ == '__main__':
    ip = input.take_input()

You will call the command -您将调用命令 -

pyinstaller --onefile main.py

And pyinstaller will import all the dependencies of all the files itself并且 pyinstaller 将导入所有文件本身的所有依赖项

尝试这个:

pyinstaller --onefile main_app.py

I think the solution is to edit the .spec file and run pyinstaller on the spec file instead of the individual .py files.我认为解决方案是编辑 .spec 文件并在 spec 文件上运行 pyinstaller 而不是单个 .py 文件。

You can find information about adding multiple exes to as single .spec file here: https://pyinstaller.readthedocs.io/en/v3.3.1/spec-files.html#multipackage-bundles您可以在此处找到有关将多个 exe 添加为单个 .spec 文件的信息: https ://pyinstaller.readthedocs.io/en/v3.3.1/spec-files.html#multipackage-bundles

Use the Command pyinstaller --onefile yourprogramname.py .使用命令pyinstaller --onefile yourprogramname.py Pyinstaller will Automatically import and Compile the Dependency Files. Pyinstaller 将自动导入和编译依赖文件。

I have made a small pyqt application of 5 and 6 .py files.Now I want to build them and compiled them in a single main file.Mean I have to operate them from one main window exe.我已经制作了一个包含5个和6个.py文件的小型pyqt应用程序。现在,我想构建它们并将其编译到一个主文件中。这意味着我必须从一个主窗口exe操作它们。 My .py files are connected with each other successfully.I have used pyinstaller to make the executable file, the problem is I have build each .py file into its own exe file.But I want to make a single exe file through which whole.py files operate.How to build all .py files into a single exe file.I have searched a lot but unable to resolve my issue.我的.py文件彼此成功连接。我已经使用pyinstaller制作了可执行文件,问题是我将每个.py文件都构建到了自己的exe文件中,但是我想制作一个完整的exe文件。 py文件运行。如何将所有.py文件构建为单个exe文件。我进行了很多搜索,但无法解决问题。

暂无
暂无

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

相关问题 如何使用pyinstaller将多个python文件编译成单个.exe文件 - How to compile multiple python files into single .exe file using pyinstaller 如何将多个文件夹层次结构中的所有 python 文件导入单个 pyinstaller 可执行文件? - How can I import all my python files in multiple folder hierarchy into a single pyinstaller executable? pyinstaller build生成可执行文件后添加文件的位置 - Location of the added files after the executable file is generated by pyinstaller build 在单个文件中构建多个文件,如 .py.png - Build multiple files like .py .png in a single file 如何使用py2exe将文本文件嵌入到单个可执行文件中 - How to embed a text file into a single executable using py2exe 如何使用scrapy和pyinstaller在Windows 10中创建单个可执行文件? - How to create a single executable file in windows 10 with scrapy and pyinstaller? 当我尝试使用 pyinstaller 构建可执行文件时,只创建了 a.spec 文件,如何使用 pyinstaller 构建可执行文件 - When i try to build an executable file with pyinstaller only a .spec file is created, How do i build an executable with pyinstaller 在Windows上使用pyinstaller从.py构建.dmg文件? - Build a .dmg file from .py using pyinstaller on windows? 使用pyinstaller将.py文件和.txt文件合并到.exe文件中 - Merging .py file and .txt files into .exe file using pyinstaller 如何在可执行文件中使用 pyinstaller 包含特定的 .jar 文件? - How to include specific .jar files with pyinstaller in executable file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM