Python脚本打包成Windows程序

SKILL开发

原名 PyInstaller 打包 Windows exe · 标识 pyinstaller-pack-windows

开发 未标注权限 许可证不明确
安装这个技能

把 Python 脚本(尤其是 Tkinter 等图形界面程序)打包成单文件 Windows exe,双击即可运行且不弹出命令行窗口。

一句话选型结论

按资料字段整理

Python脚本打包成Windows程序是开发类的 Agent Skill,安装方式未标注,权限级别未标注,许可证不明确,有可直接复制的安装命令。技能本质是给模型读的说明书,效果取决于模型与客户端;装完先用一个小任务验证,再放进正式流程。

分类开发 安装方式未标注 权限级别未标注权限 许可证许可证不明确
累计安装 未标注 本周 未标注
GitHub 星标 未标注 仓库 未标注
下载量 未标注 技能市场下载数
权限级别 未标注权限 安装前请确认风险范围
许可证 许可证不明确 未说明

安装

未标注
在支持 Skills 的客户端里执行,装完问一句「你有哪些技能」验证
skillhub install user_bd60432e/pyinstaller-pack-windows
  1. 1
    确认客户端支持

    确认你的客户端支持 Skills(Claude、Codex、Cursor 等),并升级到较新的版本。

  2. 2
    拿到技能文件

    执行上面的命令安装;也可以把仓库里的 SKILL.md 手动放进客户端的 skills 目录。

  3. 3
    刷新技能列表

    重新打开客户端,或刷新技能列表,让新放进来的技能被加载。

  4. 4
    验证是否生效

    问一句「你有哪些技能」,确认列表里出现它,再拿一个小任务试跑。

技能档案

开发
字段来自技能仓库与公开索引,中文说明由本站标注
作者 / 维护方user_bd60432e仓库 未标注 · 版本 未标注
宿主客户端未标注技能可被这些客户端加载
安装方式未标注安装包 community
权限级别未标注权限安装前请确认风险范围
许可证未说明许可证不明确,商用前请自行确认条款
仓库可用性available技能仓库当前是否可访问
最近核验2026-11-06上游最后核验时间 · 数据更新 2026-11-06
正文体量7.8 KBSKILL.md 原文大小,越大说明说明书写得越细

能做什么

0 项能力
上游给出的能力概览与适用场景
脚本打包成exe配置单文件无窗口运行分发图形界面程序

典型使用场景

3 类
按分类整理的常见用法,具体以 SKILL.md 为准
写代码与改 bug

按需求补代码、定位并修掉报错。

读仓库与生成改动

让模型读懂项目结构,再给出可落地的改动。

跑测试与排查故障

按现象排查问题,补测试用例并复跑。

选择建议

装之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 有可直接复制的安装命令,不用自己翻文档找入口。

先想清楚的地方

  • 没有标注权限级别,实际能做什么要装好后确认。
  • 许可证不明确,商用或二次分发前先到仓库确认条款。
  • 没有做站内核验,内容以作者仓库为准。
  • 技能只是说明书,实际效果取决于模型与客户端,装完先用小任务试一遍。

更适合

  • 需要在开发场景里给模型补一套做法的人。
  • 愿意先读一遍 SKILL.md、确认它会让模型做什么的人。

不太适合

  • 对许可证要求很严、必须明确可商用的人。
  • 只想装完就自动变强、不打算看说明书的人。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
技能权限级别安装方式累计安装宿主客户端安装命令
Python脚本打包成Windows程序当前 未标注权限 未标注 未标注 未标注 有
技能审查员 浏览器控制 ClawHub 市场 877.9 万 OpenClaw 有
Vercel React 最佳实践 浏览器控制 GitHub 仓库 849.1 万 Codex、Claude、Cursor 有
GitHub 代码协作 联网访问 ClawHub 市场 763.3 万 OpenClaw 有
网页设计指南 联网访问 GitHub 仓库 668.6 万 Codex、Claude、Cursor 有
本体论 只读 ClawHub 市场 663.7 万 OpenClaw 有

SKILL.md 全文

7.8 KB
模型实际读到的说明书原文,来自技能仓库

PyInstaller Pack Windows

Turn a Python script into a portable, double-click .exe on Windows. The
default recipe is --onefile --windowed (single file, no console).

When to use

  • A user says "打包成 exe", "make this a Windows executable", "double-click to
    run", or wants to publish a Tkinter/CLI tool without requiring Python install.
  • Setting up a repeatable local build (build_exe.cmd) or CI auto-build.

Core build command

python -m PyInstaller --noconfirm --onefile --windowed ^
  --name appname ^
  --icon "absolute\path\to\icon.ico" ^
  --distpath dist --workpath build_tmp --specpath build_tmp ^
  app.pyw

For a fully portable build_exe.cmd (relative paths, auto-detect python, builds
to the user's Desktop), copy references/build-exe-cmd.md and save it as
build_exe.cmd, then adjust the two script names.

Critical pitfalls (read before debugging)

See references/gotchas.md for the full list. The two that bite most often:

  1. --icon relative path fails. PyInstaller resolves a relative --icon
    against --workpath, not the current directory. Always pass an absolute
    path. In CI use "$env:GITHUB_WORKSPACE\icon.ico" (runner env var) rather
    than a GitHub Actions expression.
  2. Frozen sys.executable is the exe itself. If the app shells out to a
    Python script, _host_python() must fall back to the real interpreter
    (e.g. C:\Python313\python.exe), not sys.executable.

Tkinter note

Package with the system Python that actually has tkinter. Managed/isolated
Pythons (e.g. WorkBuddy's bundled 3.13.12) often omit tkinter, so the frozen exe
will crash on import. Verify with python -c "import tkinter".

Icons: --icon is only half the job

--icon sets the exe file icon (Explorer/desktop). The running window
title bar keeps Tk's default blue-feather icon unless you set it in code:

self.iconphoto(True, tk.PhotoImage(data=ICON_PNG_B64, format="png"))

Keep references to the PhotoImage objects (store on self) or they get
garbage-collected and the icon reverts. Embedding base64 PNGs in the source
keeps the exe self-contained. Generating the PNGs: use the zero-dep-icon-gen
skill; packing PNGs into .ico: 32bpp BMP entries (.NET's
System.Drawing.Icon reads PNG-compressed entries unreliably), and swap R/B
channels when copying PNG rows into BMP (RGBA → BGRA) or colors come out
inverted.

Desktop still shows the old default icon? It's the shell cache

Symptom: rebuild with --icon succeeds, but Explorer/desktop still shows the
PyInstaller default yellow-folder icon (or a different app's icon, if the
cache entry was keyed off an older same-named file). The exe itself is fine —
Explorer reads icons through a path-keyed cache and does not invalidate on
file replace.

Diagnose before touching anything (pure ctypes, no .NET): call
SHGetFileInfoW(path, SHGFI_ICON|SHGFI_USEFILEATTRIBUTES), pull the HICON's
color bitmap via GetIconInfo+GetDIBits, and count pixels by hue. If the
pixels match your new icon (e.g. indigo ~84% / white ~14% / yellow 0%), the
problem is purely the display cache. Notes: Add-Type may be blocked by the
sandbox security policy — use ctypes.windll.shell32 from Python instead, and
set argtypes/restype or 64-bit handles get truncated (OverflowError: int too long to convert). In this sandbox even the real-access mode (without
SHGFI_USEFILEATTRIBUTES) fails with ERROR_NO_TOKEN (1008) on every path —
the attribute-simulated mode still returns the correct cached icon, so use it
for pixel probing.

Fix — clear the whole cache family, not one file. On Windows 10/11 the
icon cache is NOT a single IconCache.db (that legacy file is ignored); it is
a set of per-size files under
%LOCALAPPDATA%\Microsoft\Windows\Explorer\:

iconcache_16.db  iconcache_32.db  iconcache_48.db  iconcache_96.db
iconcache_256.db iconcache_768.db iconcache_1280.db iconcache_1920.db ...
iconcache_idx.db iconcache_sr.db iconcache_wide.db iconcache_wide_alternate.db
iconcache_custom_stream.db iconcache_exif.db

The desktop shows large icons (reads iconcache_48.db), list views read
iconcache_16.db — which is exactly why a stale rebuild can look correct in a
folder window while the desktop still shows the old icon. Reliable sequence:

Stop-Process -Name explorer -Force
$dir = "$env:LOCALAPPDATA\Microsoft\Windows\Explorer"
$bak = "<project>\tmp\_iconcache_backup"   # MOVE, don't delete
New-Item -ItemType Directory -Force -Path $bak | Out-Null
Get-ChildItem $dir -Filter "iconcache_*.db" | ForEach-Object {
    Move-Item $_.FullName -Destination $bak -Force }
Start-Process explorer

Two traps when scripting this:

  1. Delete can fail closed. A sandbox safe-delete policy may force trash
    semantics, and the recycle-bin API needs explorer running — but you just
    stopped it, so Remove-Item aborts with SAFE_DELETE_FAIL_CLOSED and the
    loop dies halfway (leaving some caches old). Move to a backup dir
    instead
    — moving isn't delete, and you keep a rollback copy.
  2. SHChangeNotify(SHCNE_ASSOCCHANGED) alone usually does NOT clear a stale
    per-file entry. After explorer restarts, additionally push
    SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATHW, "C:\Users\DELL\Desktop", NULL)
    (ctypes: SHCNE_UPDATEDIR=0x1000, SHCNF_PATHW=5 lets you pass a path
    string instead of a PIDL) so the desktop view re-reads the folder.

Before assuming the cache is stale, confirm you're looking at the new file
(md5 vs dist/) — copying the exe to Desktop and then rebuilding leaves the
Desktop copy on the old build. Note Windows copy preserves the source mtime,
so a replaced same-path file can keep an "unchanged" cache key.

Version management

Keep a single source of truth version.py (__version__ = "1.0.0"). The app
imports it and shows it in the title/About. On release, CI rewrites it from the
git tag (see assets/version.py). Import defensively:

try:
    from version import __version__ as APP_VERSION
except Exception:
    APP_VERSION = "dev"

CI auto-build + Release

assets/build-exe.yml is a ready workflow: runs on windows-latest, builds both
exes, uploads an Actions Artifact on every main push, and attaches the exes to
any published GitHub Release. It stamps the version first (tag on release,
-dev suffix on push). Requirements:

  • Runner must be windows-latest — real .exe can only be produced on
    Windows.
  • Grant permissions: contents: write so gh release upload can attach assets.
  • If the repo .gitignore ignores everything by default, whitelist
    !version.py, !.github/, !.github/**.

Deliverable checklist

  • [ ] --onefile --windowed, absolute --icon.
  • [ ] Build script copies the exe to a known location (Desktop) or CI uploads it.
  • [ ] version.py present and imported defensively.
  • [ ] (Optional) CI workflow added and validated by a test push.

常见问题

5 问
答案由本站依据条目字段整理
Python脚本打包成Windows程序怎么安装?

在支持 Skills 的客户端里执行:skillhub install user_bd60432e/pyinstaller-pack-windows。安装方式为未标注。装完刷新技能列表或重开客户端。

Python脚本打包成Windows程序支持哪些客户端?

资料没有标注宿主客户端,但只要客户端支持 Skills(Claude、Codex、Cursor 等),一般都能加载。

Python脚本打包成Windows程序权限高吗,安全吗?

权限级别为未标注权限。安装前先看它会读取或写入哪些内容。

Python脚本打包成Windows程序收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于技能本身和所用的模型或客户端,正式使用前按作者说明确认。

Python脚本打包成Windows程序用什么许可证?

许可证标注为 未说明(许可证不明确)。商用或二次分发前请到仓库确认条款原文。

热门专题

按场景挑技能
全部专题 →

技能内容以作者仓库为准;分类、权限级别与许可证状态的中文说明为中文整理,最近核验 2026-11-06。