Search code examples
python-3.xwindowskivypyinstallerpython-packaging

Pyinstaller : Kivy: AttributeError: 'NoneType' object has no attribute 'clearcolor'


I am trying to package a kivy based python application for windows using auto-py-to-exe. auto-py-to-exe uses Pyinstaller for packaging. So after packaging the application and trying to run the created executable file of the application, I encounter this error:

File "desktop.py", line 356, in <module>
AttributeError: 'NoneType' object has no attribute 'clearcolor'

which in the actual code in desktop.py refers to:

from kivy.core.window import Window

....something....

if __name__ == "__main__":
    .... something

    Window.clearcolor = (1, 1, 0.99, 1)

    ....something

Here I am trying to provide close to white color background to the window.

I have checked for proper installation of kivy and availability of kivy.core.window module in site-packages of python. I have read at severals places to use the package-name in --hidden-import as sometimes modules may not be picked due incorrect path or other issues, so I have tried passing this module as --hidden-import "kivy.core.window" and also tried --add-data flag as --add-data "C:/Python3/Lib/site-packages/kivy/core/window;window/" to forcefully include kivy.core.window. However no luck and I still getting the same error.

If I am not mistaken the above mentioned error means the code get Nonetype when it tries to access window although the module is present at right place i.e. after packaging it is present in the package along with other kivy modules.

Also when I run the script from some IDE it works fine.

I have followed this document for debugging the Pyinstaller warnings/errors.

Config: Windows10, Python3.4, kivy 1.11.1

What am I missing or how can I specify executable to look for the file at the correct path?


Solution

  • So after @inclement's comment : to remove the line After removing this line I get [CRITICAL] [App ] Unable to get a Window, abort. . I have browsed this error and found different solution referring to sdl2.dll here. So I went ahead and added path to .dll files for sdl2, glew and angle in Windows environment variable path PATH = C:\Python3\share\sdl2\bin and so on for glew and angle. So all the .dll files are imported properly and it works fine.