Skip to content

Commit

Permalink
fix:修复exe打包问题
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyumc committed Nov 21, 2024
1 parent 76d2e7f commit 4ef663b
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions jyy_slide_web.spec
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,60 @@ 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,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='jyy_slide_web'
name='jyy_slide_web' # 输出文件夹名称
)

0 comments on commit 4ef663b

Please sign in to comment.