Files
deskflow/py2exe.py
2026-04-09 10:37:51 +08:00

47 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import time
import os
from PyInstaller import __main__ as pyi
def create_executable(script, output_name, icon, data_files,module_args_files):
data_args = []
for src, dest in data_files:
sep = ';' if os.name == 'nt' else ':' # 根据操作系统选择分隔符
data_args.extend(['--add-data', f'{src}{sep}{dest}'])
module_args = []
for moduls_file in module_args_files:
module_args.extend(['--hidden-import', f'{moduls_file}'])
# module_args.extend(['excludes', f'PyQt5'])
pyi.run([
*data_args, # 包含的静态文件
*module_args, #包含的库
'--onefile', #将所有依赖打包为单个可执行文件
# '--onedir', #打包为文件夹(默认方式),包含 exe + 依赖库 / 文件夹
'--clean',
# '--windowed', # 隐藏控制台窗口GUI 应用必备)
'--console', # 显示控制台窗口
# f"--exclude-module=PyQt5", # 排除指定库
f'--icon={icon}', # 设置程序icon
f'--name={output_name}',
script,
])
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
if __name__ == "__main__":
# 示例数据文件列表
data_files = [
("static", "static"),
("templates", "templates"),
("assets", "assets"),
("module", "module"),
]
import_modules = [
"pystray","pillow","pywebview","aiortc","opencv-python","numpy","mss"
]
create_executable(f"app.py", f"fooDesk_{int(time.time())}", "icon.ico", data_files,import_modules)