From 4ef663b619891b36de5fb5d1fc4a344cc5f71462 Mon Sep 17 00:00:00 2001 From: mona233 Date: Thu, 21 Nov 2024 16:43:30 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8Dexe=E6=89=93?= =?UTF-8?q?=E5=8C=85=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jyy_slide_web.spec | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/jyy_slide_web.spec b/jyy_slide_web.spec index ed9d8e0..4966071 100755 --- a/jyy_slide_web.spec +++ b/jyy_slide_web.spec @@ -37,44 +37,54 @@ add_data_dir('jyy_slide_web', 'jyy_slide_web') # 添加收集后的静态文件目录 add_data_dir('staticfiles', 'staticfiles') -# 如果有媒体文件夹,添加 media 目录 +# 添加媒体文件目录 add_data_dir('media', 'media') +# 添加 default_content.md 文件 +default_content_path = os.path.join('slideapp', 'default_content.md') +if os.path.exists(default_content_path): + datas.append((default_content_path, 'slideapp')) +else: + print(f"Warning: File '{default_content_path}' does not exist, skipped.") + # 如果使用 SQLite 数据库,确保数据库文件不被打包,以免覆盖用户数据 db_file = os.path.join(project_root, 'db.sqlite3') if os.path.exists(db_file): datas.append((db_file, '.')) else: print(f"Warning: Database file '{db_file}' does not exist, skipped.") -# 可以在初次运行时创建数据库,或者在打包前复制数据库文件到目标机器 +# 创建打包分析对象 a = Analysis( - ['run_daphne.py'], - pathex=[project_root], - binaries=[], - datas=datas, - hiddenimports=hiddenimports, - hookspath=[], - runtime_hooks=[], - excludes=[], - cipher=block_cipher, - noarchive=False + ['run_daphne.py'], # 主入口文件 + pathex=[project_root], # 搜索路径 + binaries=[], # 需要额外的二进制文件 + datas=datas, # 数据文件 + hiddenimports=hiddenimports, # 隐藏导入 + hookspath=[], # 自定义hook路径 + runtime_hooks=[], # 运行时hook + excludes=[], # 排除的模块 + cipher=block_cipher, # 加密方法 + noarchive=False # 是否生成单文件 ) +# 创建 PyInstaller 打包步骤 pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) +# 可执行文件的配置 exe = EXE( pyz, a.scripts, [], exclude_binaries=True, - name='jyy_slide_web', + name='jyy_slide_web', # 可执行文件名称 debug=False, strip=False, upx=True, - console=True + console=True # 是否显示控制台窗口 ) +# 打包成一个文件夹 coll = COLLECT( exe, a.binaries, @@ -82,5 +92,5 @@ coll = COLLECT( a.datas, strip=False, upx=True, - name='jyy_slide_web' + name='jyy_slide_web' # 输出文件夹名称 ) \ No newline at end of file