[英]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.