Skip to main content
TopMiniSite

Back to all posts

How to Add Folder Using Pyinstaller Command?

Published on
3 min read

Table of Contents

Show more
How to Add Folder Using Pyinstaller Command? image

To add a folder using PyInstaller command, you can specify the folder path in the command line. When running PyInstaller, you can use the --add-data flag followed by the path to the folder you want to include. For example, if you have a folder named "images" that you want to add, you can use the following command:

pyinstaller --onefile --add-data "images;images" your_script.py

This command tells PyInstaller to add the "images" folder to the bundled executable. The first "images" before the semicolon specifies the source folder location, and the second "images" after the semicolon specifies the destination folder name. This way, when the program is run, the "images" folder will be included in the executable and accessible to your script.

How to include a folder in PyInstaller build in a single command?

Unfortunately, PyInstaller does not have a built-in option to include an entire folder in a single command. However, you can achieve this by using the --add-data flag to include all the files in a folder.

Here's an example command to include an entire folder named data_folder in the PyInstaller build:

pyinstaller --onefile --add-data "data_folder;data_folder" your_script.py

In this command:

  • --onefile flag creates a single standalone executable file
  • --add-data "data_folder;data_folder" flag specifies that all files in the data_folder should be included in the build. The first data_folder is the source directory, and the second one is the destination directory in the build.

Replace your_script.py with the name of your Python script. This command will include all files in the data_folder in the PyInstaller build.

What is the command syntax for adding a folder in PyInstaller build?

The command syntax for adding a folder in PyInstaller build is as follows:

pyinstaller --add-data "path_to_folder;folder_name" your_script.py

Explanation:

  • pyinstaller: command to run PyInstaller
  • --add-data: option to add a folder into the build
  • "path_to_folder;folder_name": specify the path to the folder that you want to add and the name of the folder in the build
  • your_script.py: the name of the script file that you want to bundle into an executable

For example, if you want to add a folder named "images" located at "C:\Users\Username\Project\images" into the PyInstaller build, the command would be:

pyinstaller --add-data "C:\Users\Username\Project\images;images" your_script.py

How to add a folder to a PyInstaller command?

To add a folder to a PyInstaller command, you can use the --add-data flag followed by the path to the folder you want to include. Here is an example command to add a folder named data_folder to a PyInstaller command:

pyinstaller --add-data "path/to/data_folder:data_folder" your_script.py

This command will include the data_folder directory in the packaged executable. The syntax for specifying the folder to include is source:destination, where source is the path to the folder on your system and destination is the path to the folder in the packaged executable.

Make sure to replace path/to/data_folder with the actual path to the folder you want to include, and your_script.py with the name of your Python script.