cramos24
cramos24

Reputation: 39

Subfolders flattened in PyInstaller add-data

I'm attempting to include a directory in my PyInstaller Python application using --add-data="path/to/s1/*"

This particular sub folder is structured like:

|...
|----/s1
|----|----/database
|----|----|----add.py
|----|----|----remove.py
|----|----/plot
|----|----|----bar_chart.py
|----|----|----pie_chart.py
|...

However, when doing this my subfolder structure is lost! database and plot are no longer subfolders of s1. The structure is flattened to root and all folders are stored together.

Is there any way to maintain my original sub folder structure without having to reorganize my entire Python project?

Upvotes: 0

Views: 693

Answers (3)

Richard Didham
Richard Didham

Reputation: 1

Don't include the * in your path. Using:

--add-data="path/to/top_layer/

will preserve the file structure properly.

Upvotes: 0

luomein
luomein

Reputation: 99

I find PyInstaller will only flatten one layer of folders, while keeping the folder tree underlying that layer. In your case, just add another layer on top of it will work.

--add-data="path/to/top_layer/*"

The 'new_layer' will be flatten. But 's1' will be kept.

|-/top_layer
|--/new_layer
|----/s1
|----|----/database
|----|----|----add.py
|----|----|----remove.py
|----|----/plot
|----|----|----bar_chart.py
|----|----|----pie_chart.py
|...

Upvotes: 0

cramos24
cramos24

Reputation: 39

Turns out I was actually able to achieve my desired output by just copying the original file structure from my src/ folder into my dist/ directory after building.

Could be a flawed solution, but I haven't discovered any issues with it so far...

Upvotes: 0

Related Questions