This answer is pretty late, but the way to add arbitrary files to a PyInstaller build is pretty clearly documented:
https://pyinstaller.readthedocs.io/en/stable/spec-files.html#adding-files-to-the-bundle
The first string in the tuple is the path to the file, the second string is the path it will have under the built package. In other words, your last line should read like this:
a.datas += [("/path/to/my_xml_file.xml", "my_xml_file.xml")]
You can also add full directories like this:
a.datas += [("/path/to/dir", "dir")]
I've added the relevant part of the docs below.
To add files to the bundle, you create a list that describes the files and supply it to the Analysis
call.
You provide a list that describes the files as the value of the datas=
argument to Analysis
. The list of data files is a list of tuples. Each tuple has two values, both of which must be strings:
- The first string specifies the file or files as they are in this system now.
- The second specifies the names of the files in the bundled app at run-time.
For example, to add a single README file to a one-folder app, you could modify the spec file as follows:
a = Analysis(...
datas=[ ('src/README.txt', 'README') ],
hiddenimports=...
)
You have made the datas=
argument a one-item list. The item is a tuple in which the first string says the existing file is src/README.txt
. This file will be copied into the bundle with name README
.
The spec file is more readable if you create the list of added files in a separate statement:
added_files = [
( 'src/README.txt', 'README' )
]
a = Analysis(...
datas= added_files,
...
)
The strings may use either /
or \
as the path separator character. You can specify input files using "glob" abbreviations. When the input is multiple files, the output string may be the name of a folder. For example to include all the .mp3
files from a certain folder:
added_files = [
( '/mygame/sfx/*.mp3', 'sfx' ),
( 'src/README.txt', 'README' )
]
All files matching /mygame/sfx/*.mp3
will be copied into the bundle and stored in a folder named sfx
.
The path to the input file or folder may be absolute as in the first tuple, or relative as in the second. When it is relative, it is taken as relative to the location of the spec file.
You can also include the entire contents of a folder:
added_files = [
( '/mygame/data', 'data' ),
( '/mygame/sfx/*.mp3', 'sfx' ),
( 'src/README.txt', 'README' )
]
All files in /mygame/data
will be copied recursively into a folder named data
in the bundle.