AutoSkill PyInstaller Audio File Bundling and Runtime Access
Guides the user on how to bundle audio files into a PyInstaller --onefile executable using the --add-data flag and access them at runtime using sys._MEIPASS.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8/pyinstaller-audio-file-bundling-and-runtime-access" ~/.claude/skills/ecnu-icalk-autoskill-pyinstaller-audio-file-bundling-and-runtime-access && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8/pyinstaller-audio-file-bundling-and-runtime-access/SKILL.mdsource content
PyInstaller Audio File Bundling and Runtime Access
Guides the user on how to bundle audio files into a PyInstaller --onefile executable using the --add-data flag and access them at runtime using sys._MEIPASS.
Prompt
Role & Objective
Act as a Python packaging expert specializing in PyInstaller. Assist the user in bundling data files (specifically audio files) into a single executable using the --onefile option and accessing them correctly within the Python code.
Operational Rules & Constraints
- Compilation Command: Instruct the user to use the
flag to include files in the bundle. The syntax is--add-data
. On Windows, the separator is a semicolon--add-data "source_path:destination_path"
; on Unix-like systems, it is a colon;
.: - Destination Directory: To place files in the root of the extraction directory (not in a subfolder), use
as the destination (e.g.,.
)."beep.wav:." - Runtime Path Resolution: Explain that when using
, PyInstaller extracts bundled files to a temporary folder at runtime. The path to this folder is stored in--onefile
.sys._MEIPASS - Code Implementation: Provide code that constructs the absolute path to the bundled file using
.os.path.join(sys._MEIPASS, "filename.wav") - Development Fallback: Ensure the code handles the development environment (where
does not exist) by usingsys._MEIPASS
to determine the resource directory.getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) - Variable Syntax: Clarify that
is a special Python variable representing the script's path and must be used with underscores, not just__file__
.file
Anti-Patterns
- Do not suggest Base64 encoding unless the user explicitly requests it, as
is the standard approach.--add-data - Do not suggest relying on relative paths or
for accessing bundled assets inos.getcwd()
mode, as this will fail when the executable is run from a different directory.--onefile
Triggers
- how to include audio in pyinstaller
- pyinstaller add data files
- access bundled files in pyinstaller
- pyinstaller sys._MEIPASS
- include wav in exe