I have a trouble with pyinstaller when adding some data files like images and txts to python program. For example, I have created a toolbar with icons, and I store them in a seperate folder named images. Also I have some some txt and xml files to store some configurations. These txt ant xml files are stored in another folder named data_files. All the py files are stored in another folder named source.
When I am trying to build this python program with pyinstaller, pyinstaller can successfully build all of the source folder, but the images and data_files folders can not be built. I checked the documentation of pyinstaller but I could not find any solution. I have made a lot of google searches and found only this resourse as helpful, but this is a very inadequate resource.
My main question is: How can I build an exe file with a separately built folder such as images and confs by using pyinstaller?
Edit: I found the solution. When you create the spec file you have to a.datas parameter.
# -*- mode: python -*-
a = Analysis([os.path.join(HOMEPATH,'support/_mountzlib.py'), os.path.join(HOMEPATH,'support/useUnicode.py'), '/home/vmode/Desktop/derlem2/sources/TextSTAT.py'],
pathex=['/home/pyinstaller'])
a.datas += [("Images/New.gif","/home/vmode/Desktop/derlem2/Images/New.gif","DATA")]
a.datas += [("Images/Open.gif","/home/vmode/Desktop/derlem2/Images/Open.gif","DATA")]
a.datas += [("Images/Column.gif","/home/vmode/Desktop/derlem2/Images/Column.gif","DATA")]
pyz = PYZ(a.pure)
exe = EXE( pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=os.path.join('dist', 'TextSTAT'),
debug=False,
strip=False,
upx=True,
console=1 )
The above spec code is designed for my project. As seen in this spec code I have included 3 icons to build with the python program. When the programme is generated there is a standalone executable file with embedded these icons.
But what if we have so many files? Suppose that we have 1000 icons to use in our program. It is very inadequate to write down to spec file by hand. There must be a loop system to read the file directory and add these files dynamically. But I could not find how to add these files dynamically. There is no any chance to add these so many files by hand I think. If anyone knows please share.