"""
autoResign 工程打包方案
"""
import os
import shutil
import sys
import PyInstaller.__main__
# 1. 安装必要依赖
# pip install pyinstaller
# pip install pywin32 (Windows签名需要)
# 2. 打包配置
def package_project():
# 工程文件列表(根据实际调整)
resource_files = [
"hap-sign-tool.jar",
"OpenHarmony.p12",
"OpenHarmonyApplication.pem",
"OpenHarmonyProfileDebug.pem",
"OpenHarmonyProfileRelease.pem",
"README_ZH.md",
"resign.p7b",
"SgnedReleaseProfileTemplate.p7b",
"UnsgnedDebugProfileTemplate.json",
"UnsgnedReleasedProfileTemplate.json",
"命令.txt"
]
try:
import PIL
except ImportError:
print("⚠️ 检测到缺少 Pillow 库,正在安装...")
import subprocess
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "Pillow"])
print("✅ Pillow 安装成功")
except Exception as e:
print(f"❌ Pillow 安装失败: {str(e)}")
print("⚠️ 将跳过图标处理")
# 从参数中移除图标选项
resource_files = [arg for arg in resource_files if not arg.startswith("--icon")]
# 创建临时资源目录
resource_dir = "app_resources"
os.makedirs(resource_dir, exist_ok=True)
# 复制资源文件到临时目录
for file in resource_files:
if os.path.exists(file):
shutil.copy(file, resource_dir)
else:
print(f"⚠️ 警告:文件不存在 - {file}")
# PyInstaller配置选项
pyinstaller_args = [
"autoResign_exe.py", # 主程序入口
"--onefile", # 打包为单个可执行文件
"--name=autoResign_exe", # 生成的可执行文件名
"--add-data", f"{resource_dir}{os.pathsep}.", # 包含资源目录
"--icon=app_icon.ico", # 图标文件(可选)
"--console", # 显示控制台窗口
# "--noconsole", # 无控制台版本(GUI应用)
"--clean", # 清理临时文件
"--distpath=dist" # 输出目录
]
# 添加Windows签名支持(可选)
if os.name == "nt":
pyinstaller_args.extend([
"--uac-admin", # 请求管理员权限
"--version-file=version_info.txt" # 版本信息文件
])
# 3. 执行打包命令
print("🚀 开始打包工程...")
PyInstaller.__main__.run(pyinstaller_args)
# 4. 清理临时文件
print("🧹 清理临时文件...")
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree(resource_dir, ignore_errors=True)
os.remove("autoResign_exe.spec")
print("✅ 打包完成!可执行文件位于 dist/autoResign_exe.exe")
# 5. 版本信息文件(version_info.txt)示例内容
"""
VSVersionInfo(
ffi=FixedFileInfo(
filevers=(1, 0, 3, 0),
prodvers=(1, 0, 0, 0),
mask=0x3f,
flags=0x0,
OS=0x40004,
fileType=0x1,
subtype=0x0,
date=(0, 0)
),
kids=[
StringFileInfo(
[
StringTable(
u'040904b0',
[StringStruct(u'CompanyName', u'Your Company'),
StringStruct(u'FileDescription', u'Auto Resign Tool'),
StringStruct(u'FileVersion', u'1.0.3'),
StringStruct(u'InternalName', u'autoResign_exe'),
StringStruct(u'LegalCopyright', u'© 2025 Your Company'),
StringStruct(u'OriginalFilename', u'autoResign_exe.exe'),
StringStruct(u'ProductName', u'Auto Resigner'),
StringStruct(u'ProductVersion', u'1.0.0')])
]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
"""
if __name__ == "__main__":
package_project()
打包的exe无法在无python环境的电脑上运行,请帮忙修复
最新发布