Kivy:打包Windows版应用程序时,Builder.load_file('*.kv')抛出FileNotFoundError [英] Kivy: Builder.load_file('*.kv') throws a FileNotFoundError when packaging app for Windows
问题描述
我正在尝试为Windows打包我的应用程序,但是运行生成的.exe文件时,我始终收到此错误.该文件确实存在于项目目录中,并且在直接运行main.py时可以正常工作.在我的main.py文件中,我调用了Builder.load_file('home_screen.kv'),这似乎是引发错误的地方.
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
此问题并非特定于home_screen.kv,因为即使我在以下行中删除该行,Builder.load_file('create_schedule.kv')也会引发相同的错误.
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.
推荐答案
在您的.spec
文件中,在Analysis
中添加一行,例如:
In your .spec
file add a line in the Analysis
like:
datas=[('*.kv', '.')],
这将包括home_screen.kv
(假定它与main.py
在同一目录中).
This will include the home_screen.kv
(assuming it is in the same directory as your main.py
).
这篇关于Kivy:打包Windows版应用程序时,Builder.load_file('*.kv')抛出FileNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!