python - 如何使用pyinstaller将多个python文件编译成单个.exe文件

标签 python python-2.7 tkinter pyinstaller

我在 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/

相关文章:

python - 解析嵌套的 JSON 数据

applymap 中的 Python 引用行

python - 如何获得具有相同最高值的所有键?

python - 如何在 tkinter - python 中添加多个 block

python - 调整窗口大小时垂直增长小部件(使用网格几何管理器)

python - 如何使用 zcat 在 Python 中测试 gzip 文件目录并解压缩 gzip 文件?

python : print output of each thread to seperate file

Python如何过滤特定警告?

multithreading - 如何安全管理wxPython进度对话框线程?

python - 带进度条的 Tkinter GUI