I have a running kivy-app which works fine when I start it from vscode. But when I try to make an exe-file with
pyinstaller --onefile --icon=icons/levermannApp.ico --exclude-module matplotlib LevermannApp.py
And then start the program I get this error message
[CRITICAL] [Window ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
File "kivy\core\__init__.py", line 70, in core_select_lib
File "kivy\core\window\window_sdl2.py", line 152, in __init__
File "kivy\core\window\__init__.py", line 982, in __init__
File "kivy\core\window\window_sdl2.py", line 311, in create_window
File "kivy\core\window\__init__.py", line 1268, in create_window
File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
File "kivy\core\image\__init__.py", line 561, in __init__
File "kivy\core\image\__init__.py", line 754, in _set_filename
File "kivy\core\image\__init__.py", line 460, in load
File "kivy\core\image\__init__.py", line 223, in __init__
File "kivy\core\image\img_sdl2.py", line 47, in load
Traceback (most recent call last):
File "LevermannApp.py", line 28, in <module>
class MyLayout(Widget):
File "LevermannApp.py", line 29, in MyLayout
Window.size = (550, 700)
AttributeError: 'NoneType' object has no attribute 'size'
[49080] Failed to execute script LevermannApp
Part of my code looks like this:
class MyLayout(Widget):
Window.size = (550, 700)
class LevermannScore(App):
def build(self):
return MyLayout()
if __name__ == "__main__":
LevermannScore().run()
My spec-file looks like this:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['LevermannApp.py'],
pathex=['C:\\Users\\Polzi\\Documents\\DEV\\Python-Private'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=['matplotlib'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='LevermannApp',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True , icon='icons\\levermannApp.ico')
Any ideas why the program is running fine with vscode but not as executable? (In the past I already was able to make an exe-file with pyinstaller for this program - but now I try it again and get the above error...)
I think finally i was able to solve it py defining the spec-file as following:
# -*- mode: python -*-
import os
from kivy_deps import sdl2, glew
spec_root = os.path.abspath(SPECPATH)
block_cipher = None
app_name = 'LevermannApp'
win_icon = 'icons/levermannApp.ico'
a = Analysis(['LevermannApp.py'],
pathex=['C:\\Users\\Polzi\\Documents\\DEV\\Python-Private'],
binaries=None,
datas=[('*.kv', '.')],
hiddenimports=['win32timezone'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name=app_name,
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=False,
icon=win_icon)
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=False,
name=app_name)
And then start simply the compilation with the command
pyinstaller LevermannApp.spec
By the way with this it is not compiled into a single exe-file (which i have normaly when using pyinstaller) - but this is no big problem for me and the exe-file is working fine. (i will use it together with Inno Setup to compile it finally to a setup.exe)