I'm struggling with pyinstaller. Whenever I build this specific script with a kivy GUI and a .kv file, and run the .exe after the build, I get a fatal error:
IOError: [Errno 2] No such file or directory: 'main.kv'
I've tried adding the .kv file, as well as a mdb and dsn file (for pypyodbc) using --add-data, but I get an error: unrecognized arguments: --add-data'main.kv'
. (There were more --add-data arguments for the other files mentioned.)
Are there any solutions for this or maybe alternative methods?
Getting back to adding data files We need to add data files such as help file or icon file or README files to pyinstaller. That's pretty simple. Just use the add-data flag while building your binaries. The separator is different for windows and posix based systems.
You can add binary files to the bundle by using the --add-binary command option, or by adding them as a list to the spec file. In the spec file, make a list of tuples that describe the files needed. Assign the list of tuples to the binaries= argument of Analysis.
Explanation. pathex is an optional list of paths to be searched before sys.path. Source: https://github.com/pyinstaller/pyinstaller/blob/develop/PyInstaller/building/build_main.py#L123. The spec file is actually executable Python code. PyInstaller builds the app by executing the contents of the spec file.
As others (@Anson Chan, @schlimmchen) have said:
If you want to add some extra files, you should use Adding Data Files.
--add-data
datas=
pyinstaller
the first time. *.spec
file.pyinstaller
will directly use your *.spec
file.Parameter
LogicParameter in --add-data
or datas=
:
--add-data
: {source}{os_separator}{destination}
os_separator
: ;
:
source
and destination
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. 'src/README.txt:.'
'/mygame/sfx/*.mp3:sfx'
/mygame/data:data'
datas=
added_files = [ ( 'src/README.txt', '.' ), ( '/mygame/data', 'data' ), ( '/mygame/sfx/*.mp3', 'sfx' ) ] a = Analysis(... datas = added_files, ... )
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", "."], ... )
If you check pyinstaller -h
for help, you can find --add-data
option works like this [--add-data <SRC;DEST or SRC:DEST>]
. So in your case try
pyinstaller -F --add-data "main.kv;main.kv" yourtarget.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With