-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoolbox.spec
More file actions
286 lines (260 loc) · 7.66 KB
/
Copy pathtoolbox.spec
File metadata and controls
286 lines (260 loc) · 7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# -*- mode: python ; coding: utf-8 -*-
"""
工具箱 (Toolbox) PyInstaller 配置文件
用于打包 PyQt6 桌面应用程序
使用方法:
pyinstaller toolbox.spec
特性:
- 单文件可执行程序
- 包含 plugins 目录和 config.py
- 包含版本信息和应用元数据
- 排除不必要的模块以减小体积
- 支持 Windows 和 macOS
- UPX 压缩启用
- Strip 调试符号
优化说明:
1. 排除了不需要的 GUI 框架(tkinter)
2. 排除了测试框架和开发工具
3. 排除了不需要的网络协议模块
4. 排除了所有不需要的 PyQt6 模块(只保留 QtCore、QtGui、QtWidgets)
5. 排除了科学计算库(numpy、pandas、matplotlib 等)
6. 启用 strip 移除调试符号
7. 启用 UPX 压缩(但排除关键 DLL 以避免启动问题)
8. 优化级别设置为 2(最高)
注意:保留了 PyInstaller 需要的核心模块(zipfile、inspect、io 等)
预期效果:
- 原始大小: ~250MB
- 优化后: ~80-100MB(减少约 60%)
- 更保守的排除策略确保稳定性
"""
import sys
import os
# 将项目根目录加入 sys.path,确保能导入 config.py
_spec_dir = os.path.abspath('.')
if _spec_dir not in sys.path:
sys.path.insert(0, _spec_dir)
# 从 config.py 导入应用信息
try:
from config import APP_NAME, APP_VERSION, APP_DESCRIPTION, APP_COPYRIGHT
except ImportError:
APP_NAME = "工具箱"
APP_VERSION = "2.0.0"
APP_DESCRIPTION = "批量处理工具"
APP_COPYRIGHT = "© 2026 yansheng836"
block_cipher = None
a = Analysis(
['main.py'], # 主入口点改为 main.py
pathex=[],
binaries=[],
datas=[
('config.py', '.'),
('toolbox.py', '.'),
('menu_system.py', '.'),
('settings_page.py', '.'),
('plugins', 'plugins'),
('favicon.ico', '.'),
],
hiddenimports=[
# 项目模块
'toolbox',
'config',
'menu_system',
'settings_page',
# 插件模块(动态加载的插件必须明确指定)
'plugins.image_scaler',
'plugins.pdf_merger',
'plugins.pdf_splitter',
'plugins.file_deduplicator',
'plugins.image_compressor',
'plugins.image_to_pdf',
'plugins.image_format_converter',
'plugins.image_stitcher',
# PIL/Pillow 核心模块
'PIL',
'PIL.Image',
'PIL.ImageFilter',
'PIL.ImageEnhance',
'PIL.ImageDraw',
'PIL.ImageFont',
# PyQt6 核心模块(确保包含)
'PyQt6.sip',
# PDF 转换库
'img2pdf',
'fitz', # PyMuPDF
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[
# GUI 框架(不需要的)
'tkinter',
'_tkinter',
# 测试框架
'unittest',
'test',
'tests',
'doctest',
'pytest',
# 开发工具
'pydoc',
'lib2to3',
'distutils',
'setuptools',
'pip',
'wheel',
'pkg_resources',
# 网络协议(不需要的)
'ftplib',
'telnetlib',
'poplib',
'imaplib',
'smtplib',
'xmlrpc',
# 数据库
'sqlite3',
# 异步/并发(如果不需要)
# 注意:某些库可能需要这些,谨慎排除
# 'asyncio',
# 'concurrent',
# 'multiprocessing',
# 科学计算库(项目不需要)
'matplotlib',
'pandas',
'numpy',
'scipy',
'sklearn',
'tensorflow',
'torch',
'keras',
# PyQt6 不需要的模块
'PyQt6.QtWebEngine',
'PyQt6.QtWebEngineCore',
'PyQt6.QtWebEngineWidgets',
'PyQt6.QtNetwork',
'PyQt6.QtNetworkAuth',
'PyQt6.QtPdf',
'PyQt6.QtPdfWidgets',
'PyQt6.QtSql',
'PyQt6.QtTest',
'PyQt6.QtXml',
'PyQt6.QtXmlPatterns',
'PyQt6.QtBluetooth',
'PyQt6.QtPositioning',
'PyQt6.QtQuick',
'PyQt6.QtQuickWidgets',
'PyQt6.QtQml',
'PyQt6.QtSensors',
'PyQt6.QtSerialPort',
'PyQt6.QtWebChannel',
'PyQt6.QtWebSockets',
'PyQt6.QtMultimedia',
'PyQt6.QtMultimediaWidgets',
'PyQt6.QtOpenGL',
'PyQt6.QtOpenGLWidgets',
'PyQt6.QtPrintSupport',
'PyQt6.QtDBus',
'PyQt6.QtDesigner',
'PyQt6.QtHelp',
'PyQt6.QtNfc',
'PyQt6.QtRemoteObjects',
'PyQt6.QtSvg',
'PyQt6.QtSvgWidgets',
'PyQt6.Qt3DCore',
'PyQt6.Qt3DRender',
'PyQt6.Qt3DInput',
'PyQt6.Qt3DLogic',
'PyQt6.Qt3DAnimation',
'PyQt6.Qt3DExtras',
'PyQt6.QtCharts',
'PyQt6.QtDataVisualization',
],
optimize=2,
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
# 排除不需要的 Qt6 C++ DLL 和软件 OpenGL 回退
# Qt6Pdf.dll — 项目使用 img2pdf/PyMuPDF,无需 Qt PDF 渲染引擎
# Qt6Network.dll — 项目无任何网络功能,插件级别的依赖无关紧要
# opengl32sw.dll — 多数 Windows 系统有硬件 OpenGL,无需软件回退
_excluded_dlls = frozenset({'Qt6Pdf.dll', 'Qt6Network.dll', 'opengl32sw.dll'})
a.binaries = [
entry for entry in a.binaries
if os.path.basename(entry[0]) not in _excluded_dlls
]
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
# Windows 特定配置
if sys.platform == 'win32':
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name=f'{APP_NAME}ToolBox-v{APP_VERSION}', # 包含版本号的文件名
debug=False,
bootloader_ignore_signals=False,
strip=True, # 启用 strip 以移除调试符号
upx=True, # 启用 UPX 压缩
upx_exclude=[
'vcruntime140.dll', # Windows 运行时库不压缩
'python*.dll', # Python DLL 不压缩
'Qt6Core.dll', # Qt 核心库不压缩(避免启动问题)
'Qt6Gui.dll',
'Qt6Widgets.dll',
],
runtime_tmpdir=None,
console=False, # GUI 模式
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='favicon.ico', # Windows 图标
version='version_info.txt', # 版本信息文件
)
# macOS 特定配置
if sys.platform == 'darwin':
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name=f'{APP_NAME}ToolBox-v{APP_VERSION}',
debug=False,
bootloader_ignore_signals=False,
strip=True,
upx=True,
upx_exclude=[
'python*.dll',
'Qt6Core.dylib',
'Qt6Gui.dylib',
'Qt6Widgets.dylib',
],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='favicon.ico',
)
app = BUNDLE(
exe,
name=f'{APP_NAME}.app',
icon='favicon.ico',
bundle_identifier='com.yansheng836.toolbox',
info_plist={
'CFBundleShortVersionString': APP_VERSION,
'CFBundleVersion': APP_VERSION,
'CFBundleDisplayName': APP_NAME,
'CFBundleName': APP_NAME,
'CFBundleGetInfoString': APP_DESCRIPTION,
'NSHumanReadableCopyright': APP_COPYRIGHT,
'LSMinimumSystemVersion': '10.14',
'NSHighResolutionCapable': 'True',
},
)