我在 python 中创建了一个 GUI(使用 Tkinter),它在使用 os.system('python_file.py') 从 GUI 中单击一个按钮时运行 python 文件。我想通过将 Tkinter 文件保持为主要文件,使用 pyinstaller 将所有这些 python 文件捆绑到单个 .exe 文件中。
我通过在命令行中执行以下操作创建了 .exe 文件:
pyinstaller --debug --onefile --noupx tkinter_app.py
目前我的 .spec 文件如下所示:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['tkinter_app.py'],pathex=['C:\\test'],binaries=[],datas=[],
hiddenimports=[],hookspath=[],runtime_hooks=[],excludes=[], win_no_prefer_redirects=False,
win_private_assemblies=False, cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name='tkinter_app', debug=True, strip=False, upx=False,console=True )
我不确定如何在上述 .spec 文件中包含其他 python 文件,以便整个应用程序正常工作。有人可以帮忙吗?
最佳答案
假设您有两个文件:“my_main.py” 和“my_functions.py”。假设 "my_main.py" 从 "my_functions.py"
导入方法执行以下命令:
pyinstaller --onefile my_main.py my_functions.py
生成的单个可执行文件 “my_main.exe” 将在当前工作目录的 “dist” 文件夹下创建。
Linux/Windows 的相同过程。对于两个以上的 python 文件,只需在用空格分隔后包含一个。
pyinstaller --onefile my_main.py my_functions.py file3.py file4.py
关于python - 如何使用pyinstaller将多个python文件编译成单个.exe文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45183137/