As others (@Anson Chan, @schlimmchen) have said:
If you want to add some extra files, you should use Adding Data Files.
Two ways to implement
- Command Line: add parameter to
--add-data
- Spec file: add parameter to
datas=
- Generated when running
pyinstaller
the first time.
- Then later you can edit your
*.spec
file.
- Then running
pyinstaller
will directly use your *.spec
file.
Parameter
Logic
Parameter in --add-data
or datas=
:
--add-data
:
- format:
{source}{os_separator}{destination}
os_separator
:
- Windows:
;
- Mac/Linux/Unix:
:
source
and destination
- Logic:
source
: path to single or multiple files, supporting glob syntax. Tells PyInstaller where to find the file(s).
destination
file or files: destination folder which will contain your source files at run time.
* NOTE: NOT the destination file name.
- folder: destination folder path, which is RELATIVE to the destination root, NOT an absolute path.
- Examples:
- Single file:
'src/README.txt:.'
- multiple files:
'/mygame/sfx/*.mp3:sfx'
- folder:
/mygame/data:data'
datas=
- Format: list or tuple.
- Examples: see the following.
added_files = [
( 'src/README.txt', '.' ),
( '/mygame/data', 'data' ),
( '/mygame/sfx/*.mp3', 'sfx' )
]
a = Analysis(...
datas = added_files,
...
)
Your case
For your (Windows OS) here is:
--add-data
in command line
pyinstaller -F --add-data "main.kv;." yourtarget.py
OR:
datas=
in yourtarget.spec
file, see following:
a = Analysis(...
datas = ["main.kv", "."],
...
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…