Including a directory using Pyinstaller
Paste the following after a = Analysis()
in the spec file to traverse a directory recursively and add all the files in it to the distribution.
##### include mydir in distribution #######def extra_datas(mydir): def rec_glob(p, files): import os import glob for d in glob.glob(p): if os.path.isfile(d): files.append(d) rec_glob("%s/*" % d, files) files = [] rec_glob("%s/*" % mydir, files) extra_datas = [] for f in files: extra_datas.append((f, f, 'DATA')) return extra_datas############################################ append the 'data' dira.datas += extra_datas('data')
I'm suprised that no one mentioned the official supported option using Tree()
:
https://stackoverflow.com/a/20677118/2230844
https://pyinstaller.readthedocs.io/en/stable/advanced-topics.html#the-toc-and-tree-classes
Yes, you can just add directories to the Analysis object and they get copied across.
a = Analysis(['main.py'], datas = [('test/dir', 'test/dir')], ...)