Editor

Build the --add-data Options

Beginner · Write the code · from tkinter to .exe with PyInstaller: Windows, macOS and Linux

From the lesson: tkinter to .exe with PyInstaller: Windows, macOS and Linux

Turn your tkinter program into an .exe, a Mac app or a Linux program that people can open with a double-click, with no Python on their computer.

Read the lesson

Your app opens resource_path("logo.png") and resource_path("sounds/ding.wav"). For each file to land where that code looks, it needs its own --add-data SOURCE:DEST, where DEST is the folder inside the bundle: logo.png:. and sounds/ding.wav:sounds.

Write add_data_args(paths) that takes the relative paths your code opens and returns the list of arguments to add to the pyinstaller command: "--add-data", then "SOURCE:DEST", for each path in order. DEST is the folder part of the path, or . when there is no folder.

add_data_args(["logo.png", "sounds/ding.wav"])
->  ['--add-data', 'logo.png:.', '--add-data', 'sounds/ding.wav:sounds']
import os
def add_data_args(paths):
# One "--add-data" and one "SOURCE:DEST" per path
pass

What Check runs

Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.

RunsExpected output
add_data_args(["logo.png"])['--add-data', 'logo.png:.']
add_data_args(["logo.png", "sounds/ding.wav"])['--add-data', 'logo.png:.', '--add-data', 'sounds/ding.wav:sounds']

More PyInstaller exercises

All Python exercises · 50 practice problems