如何使用 pyinstaller 将多个 .py 文件构建为单个可执行文件? [英] How to build multiple .py files into a single executable file using pyinstaller?

查看:61
本文介绍了如何使用 pyinstaller 将多个 .py 文件构建为单个可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个包含 5-6 个 .py 文件的小型 PyQt 应用程序.现在我想将它们构建并编译成一个主文件,这意味着它必须从一个主窗口 exe 中运行.

I have made a small PyQt application containing 5-6 .py files. Now I want to build and compile them into a single main file, meaning it has to operate from one main window exe.

我的 .py 文件相互连接成功.我已经使用 pyinstaller 来制作可执行文件,但问题是我将每个 .py 文件构建到了自己的 .exe 文件中.但我想制作一个 .exe 文件,通过它可以使用所有 .py 文件.

My .py files are connected with each other successfully. I have used pyinstaller to make the executable file, but the problem is I built each .py file into its own .exe file. But I want to make a single .exe file through which all the .py files can be used.

如何将所有 .py 文件构建到一个 .exe 文件中?

How to build all .py files into a single .exe file?

推荐答案

假设您有一个名为 create.py 的文件,例如

Suppose you had a file called create.py like

def square (num)
    return num ** 2 

同一目录中的另一个文件 input.py

Another file in the same directory called input.py

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

最后是你的 ma​​in.py

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

您将调用命令 -

pyinstaller --onefile main.py

并且pyinstaller会自己导入所有文件的所有依赖

And pyinstaller will import all the dependencies of all the files itself

这篇关于如何使用 pyinstaller 将多个 .py 文件构建为单个可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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