简体   繁体   中英

SDL2 Error: "Unable to load image <default.png>" when freezing kivy application using pyinstaller

I'm unable to produce a working exe with pyinstaller (the name of the app is settings_gui).

Runtime error: ( Full log )

[WARNING           ] [Image       ] Unable to load image <<project_path>\dist\SETTIN~1\kivy_install\data\glsl\default.png>
[CRITICAL          ] [Window      ] Unable to find any valuable Window provider
at all!
sdl2 - Exception: SDL2: Unable to load image
  File "site-packages\kivy\core\__init__.py", line 67, in core_select_lib
  File "site-packages\kivy\core\window\window_sdl2.py", line 138, in __init__
  File "site-packages\kivy\core\window\__init__.py", line 722, in __init__
  File "site-packages\kivy\core\window\window_sdl2.py", line 255, in create_wind
ow
  File "site-packages\kivy\core\window\__init__.py", line 897, in create_window
  File "kivy\graphics\instructions.pyx", line 756, in kivy.graphics.instructions
.RenderContext.__init__ (kivy\graphics\instructions.c:10729)
  File "site-packages\kivy\core\image\__init__.py", line 512, in __init__
  File "site-packages\kivy\core\image\__init__.py", line 700, in _set_filename
  File "site-packages\kivy\core\image\__init__.py", line 430, in load
  File "site-packages\kivy\core\image\__init__.py", line 198, in __init__
  File "site-packages\kivy\core\image\img_sdl2.py", line 42, in load

[CRITICAL          ] [App         ] Unable to get a Window, abort.
 Exception SystemExit: 1 in 'kivy.properties.dpi2px' ignored
[INFO              ] [Text        ] Provider: sdl2
 Traceback (most recent call last):
   File "settings_gui.py", line 26, in <module>
 AttributeError: 'NoneType' object has no attribute 'clearcolor'
Failed to execute script settings_gui

What is going wrong? I checked <project_path>/dist/settings_gui/kivy_install/data/glsl/default.png , it's there. I find it weird however that the path is SETTING~1 , is that normal? I've seen this thread which recommends to redirect the resources through _MEIPASS , but this doesn't help - expectedly, since I'm not building my app in one-file-mode.

Any tip on how to troubleshoot this is appreciated.

Edit :

More info:

  • Without pyinstaller, the app runs perfectly fine - except for when I close it or stop it otherwise; when I do that, python crashes.
  • When I build my app, a kivy window opens and crashes immediately. I always close it and the build process continues.
  • My.spec file
  • Logs of the build

I managed to fix the issue by copying file

From: [Python]\share\sdl2\bin\libpng16-16.dll
To:   [Dist]\<projectName>\libpng16-16.dll

There was an instance of the file already there but the one I replaced it with was about 20kb larger (from 198kb to 213kb).

The important part is that my app works now and I didn't change anything else.

I'm having the same issue.

From kivy docs

Alternate installations

The previous examples used eg *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins + gstreamer.dep_bins)], to make PyInstaller add all the dlls used by these dependencies. If kivy was not installed using the wheels method these commands will not work and eg kivy.deps.sdl2 will fail to import. Instead, one must find the location of these dlls and manually pass them to the Tree class in a similar fashion as the example.

Changed

*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],

to something like

Tree('C:\\Python27\\share\\sdl2\\bin\\'),
Tree('C:\\Python27\\share\\glew\\bin\\'),

It still have to close a window building in pyinstaller, but now the application .exe works

这是我的屏幕截图

I have fixed this issue, please add this code before importing kivy module:

import os
os.environ['KIVY_IMAGE'] = 'pil'

from kivy.app import App

and execute pip install pillow .

Add this code into xxx.spec file in your project directory to fixed this issue:

# -*- mode: python ; coding: utf-8 -*-
from kivy_deps import sdl2, glew       #at the beginning of xxx.spec
...
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               upx_exclude=[],
               name='KivyApp')

and then, run this command in your project directory to pack your kivy app:

 pyinstaller xxx.spec

Referenced from kivy official doc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM