I've seen some related questions here and tried every single solution I found like this and this for example, but I couldn't make that work. So the question is simple - after making single exe file from kivy it throws a FileNotFoundError: [Errno 2] No such file or directory: 'main2.kv'
. Exe file with related files works good but I don't know what am I doing wrong while building single exe.
My spec file:
# -*- mode: python ; coding: utf-8 -*-
from kivymd.tools.packaging.pyinstaller import hooks_path as kivymd_hooks_path
from kivy_deps import sdl2, glew
...
a = Analysis(['main.py'],
...
# I tried to write here absolute path, relative path and this method
datas=[('*.kv', '.')],
hiddenimports=[],
hookspath=[kivymd_hooks_path],
...
)
# I also tried to put import here - didn't help (when I did that I also tried to change the path in my .py file to 'Data\main2.kv')
# a.datas += [('main2.kv', 'D:\\prog\\Lotto\\main2.kv', 'DATA')]
...
# tried with Tree and without Tree
coll = COLLECT(exe, Tree('D:\\prog\\Lotto','Data'),
...
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
...
In .py file I tried to add
if getattr(sys, 'frozen', False):
kivy.resources.resource_add_path(sys._MEIPASS)
And
def resourcePath():
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS)
return os.path.join(os.path.abspath("."))
...
if __name__ == "__main__":
kivy.resources.resource_add_path(resourcePath())
MainApp().run()
And tried both of above methods together - nothing. Also tried to change PyInstaller 3.6 to 3.5 version. I don't know what's the problem here, it's my first time trying to make exe file from Kivy.