项目备份
This commit is contained in:
46
py2exe.py
Normal file
46
py2exe.py
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
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)
|
||||
Reference in New Issue
Block a user