Search code examples
pythonwindowskivypackaging

Kivy: Builder.load_file('*.kv') throws a FileNotFoundError when packaging app for Windows


I am attempting to package my app for windows but I keep getting this error when running the .exe file generated. The file does exist in the project directory and it works fine when running main.py directly. In my main.py I called Builder.load_file('home_screen.kv'), which is where it seems to be throwing the error.

 Traceback (most recent call last):
   File "main.py", line 46, in <module>
   File "site-packages\kivy\app.py", line 800, in run
   File "main.py", line 10, in build
   File "main.py", line 15, in __init__
   File "site-packages\kivy\lang\builder.py", line 288, in load_file
 FileNotFoundError: [Errno 2] No such file or directory: 'home_screen.kv'
[3208] Failed to execute script main

This problem is not specific to home_screen.kv since even if I remove that line the following line, Builder.load_file('create_schedule.kv'), throws the same error.


Solution

  • In your .spec file add a line in the Analysis like:

    datas=[('*.kv', '.')],
    

    This will include the home_screen.kv (assuming it is in the same directory as your main.py).