SuperAPI AI 工具集

qt-packaging

编程与开发

查看项目

更新于 10-16 06:22

技能介绍

用途:为 Qt Python 应用(如 PySide6)提供打包与分发方案,覆盖 PyInstaller 与 Briefcase 两条路线,以及各平台构建配置。

主要能力:

  • PyInstaller:强调虚拟环境隔离,构建前需卸载系统级 PySide6(pip uninstall pyside6 pyside6_essentials pyside6_addons shiboken6 -y),并用 python -c "import PySide6; print(PySide6.file)" 确认路径位于 .venv。Qt6 下 --onefile 无法自动部署 Qt 插件,推荐 one-directory。安装:uv add --dev pyinstaller。基本命令:pyinstaller --name MyApp --windowed --icon resources/icons/app.ico src/myapp/main.py。可用 .spec 文件实现可复现构建,通过 datas、hiddenimports(如 PySide6.QtSvg、PySide6.QtSvgWidgets、PySide6.QtXml、PySide6.QtPrintSupport、PySide6.QtDBus)与 excludes 控制打包内容,运行 pyinstaller MyApp.spec。
  • Briefcase:生成原生安装包(.msi、.dmg、.AppImage),命令为 briefcase create / build / run / package,并在 pyproject.toml 的 [tool.briefcase] 与 [tool.briefcase.app.myapp] 中配置项目信息、sources、requires 等;对 PySide6 的 Qt 插件打包比 PyInstaller 更可靠。
  • 平台处理:Windows 用 windeployqt dist/MyApp/MyApp.exe 补齐插件与翻译,并用 signtool 签名;macOS 用 codesign 签名 .app,必要时用 xcrun notarytool 公证;Linux 可借助 AppImageKit 的 appimagetool 打包。
  • CI:给出 GitHub Actions 构建 Windows 产物的示例流程。

常见陷阱:缺少 Qt 平台插件、缺少 SVG 支持、相对路径假设(开发用 Path(file).parent,PyInstaller 运行时用 sys._MEIPASS 或改用 QRC)、macOS 应用冻结需设 argv_emulation=True。

限制:资料未提供具体版本兼容范围、各平台完整测试结果与收费信息。