Embedding custom pptx template within executable file
I have written a code that takes several pictures from a folder and collates them into a company-specific PowerPoint template. Within the code, I am indicating the location of the template, which is in the same directory as the .py file. However, upon creating a .exe file it results in an error in the line that specifies the template of the presentation:
template = os.getcwd() + '\\template.pptx'
prs = Presentation(template) ### ERROR OCCURS HERE
Is there a way to embed my own power point template while building .exe file. I have tried putting it into .spec file, by indicating the location of the custom pptx template in datas, which I put into the site-packages as follows:

p = "C:\\Users\\<username>\\AppData\\Local\\Programs\\Python\\Python39\\Lib\\site-packages\\pptx\\templates\\my_template.pptx"
block_cipher = None
a = Analysis(['Pictures_to_Slides.py'],
pathex=[],
binaries=[],
datas=[ (p, '.\\pptx\\templates\\') ],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
After doing this the .exe file was created successfully but again resulted in error at the stage of declaring Presentation("my_template.pptx)
Does anybody have an experience with building custom pptx templates within .exe files?
I have the same issue but on macOS and without the custom template. As soon as I build a binary file to run this in a terminal window, I get these errors:
Traceback (most recent call last):
File "PP_Report_Gen.py", line 184, in
It looks like that the pyhton-pptx is looking for a default template. (/pptx/templates/default.pptx) If you could tell me where this file is located or how I can tell the program where to find it, that would be awesome.
OK, I found the solution: Iin the folder where I have the python script, I created a new folder called pptxTemplate In my code I use this to locate the template:
Get the path of the template
template_path = os.path.dirname(os.path.abspath(__file__))
Get the directory of the template
source_folder = os.path.join(template_path, "pptxTemplate")
Construct the path to the image file
template_file_path = os.path.join(source_folder, "ocuair_template.pptx")
In my def, where I create the PowerPoint, I use this:
Load the template presentation
presentation = Presentation(template_file_path)
When I compile the program I use the following command:
pyinstaller PP_Report_Gen.py \
--onefile \
--add-data="./pptxTemplate:pptxTemplate" \
--target-arch universal2 \
-n ppt-generator
Now the program works on both CPUs, Intel and Apple Silicon.
I hope this helps.