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

半世苍凉 提交于 2021-01-29 05:57:54

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/54359391/kivy-builder-load-file-kv-throws-a-filenotfounderror-when-packaging-app-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!