kivy: Buster RPi4B unable to find valuable Window provider from Desktop-less console

After logging on the Raspberry Pi 4B to the command line (using raspi-config boot to CLI), cannot execute kivy because of critical error when attempting to use any kivy Window provider: egl_rpi, sdl2, pygame, or x11. This issue lists the attempts and results of each of these Window providers. These providers are listed on the following page:

https://kivy.org/doc/stable/guide/environment.html

KIVY_WINDOW Implementation to use for creating the Window Values: sdl2, pygame, x11, egl_rpi

Versions

Description

The same test.py program listed below was used to test all of the Window providers listed above. The second line is changed for each test results.

import os
#os.environ['KIVY_WINDOW'] = 'egl_rpi'
from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
	def build(self):
		return Button(text='Hello World')

TestApp().run()

When no (default) KIVY_WINDOW defined (test.py above), gets the following results:

[DEBUG  ] [Window      ] Provider <egl_rpi> ignored by config
[DEBUG  ] [Window      ] Provider <sdl2> ignored by config
[DEBUG  ] [Window      ] Provider <x11> ignored by config
[CRITICAL] [Window      ] Unable to find any valuable Window provider. 
[CRITICAL] [App         ] Unable to get a Window, abort.

After changing line 2 by removing the # sign, got the following results:

[DEBUG  ] [Window      ] Ignored <egl_rpi> (import error)
[DEBUG  ] [Window      ] Provider <sdl2> ignored by config
[DEBUG  ] [Window      ] Provider <x11> ignored by config
[CRITICAL] [Window      ] Unable to find any valuable Window provider. 
egl_rpi - ImportError: cannot import name 'bcm' from 'kivy.lib.vidcore_lite' (/usr/local/lib/python3.7/dist-packages/kivy/lib/vidcore_lite/__init__.py)
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/__init__.py", line 63, in core_select_lib
    fromlist=[modulename], level=0)
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/window/window_egl_rpi.py", line 12, in <module>
    from kivy.lib.vidcore_lite import bcm, egl
[CRITICAL] [App         ] Unable to get a Window, abort.

After changing line 2 to os.environ['KIVY_WINDOW'] = 'sdl2', got the following results:

[DEBUG  ] [Window      ] Provider <egl_rpi> ignored by config
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[DEBUG  ] [Window      ] Provider <x11> ignored by config
[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 - RuntimeError: b'Could not initialize EGL'
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/__init__.py", line 71, in core_select_lib
    cls = cls()
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/window/window_sdl2.py", line 152, in __init__
    super(WindowSDL, self).__init__()
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/window/__init__.py", line 981, in __init__
    self.create_window()
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/window/window_sdl2.py", line 290, in create_window
    self.get_gl_backend_name())
  File "kivy/core/window/_window_sdl2.pyx", line 224, in kivy.core.window._window_sdl2._WindowSDL2Storage.setup_window
  File "kivy/core/window/_window_sdl2.pyx", line 74, in kivy.core.window._window_sdl2._WindowSDL2Storage.die
[CRITICAL] [App         ] Unable to get a Window, abort.

After changing line 2 to os.environ['KIVY_WINDOW'] = 'pygame', got the following results:

[DEBUG  ] [Window      ] Provider <egl_rpi> ignored by config
[DEBUG  ] [Window      ] Provider <sdl2> ignored by config
[DEBUG  ] [Window      ] Provider <x11> ignored by config
[CRITICAL] [Window      ] Unable to find any valuable Window provider. 
[CRITICAL] [App         ] Unable to get a Window, abort.

After changing line 2 to os.environ['KIVY_WINDOW'] = 'x11', got the following results:

[DEBUG  ] [Window      ] Provider <sdl2> ignored by config
[DEBUG  ] [Window      ] Ignored <x11> (import error)
[CRITICAL] [Window      ] Unable to find any valuable Window provider. 
x11 - ModuleNotFoundError: No module named 'kivy.core.window.window_x11'
  File "/usr/local/lib/python3.7/dist-packages/kivy/core/__init__.py", line 63, in core_select_lib
    fromlist=[modulename], level=0)
[CRITICAL] [App         ] Unable to get a Window, abort.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 113 (40 by maintainers)

Most upvoted comments

Here are the instructions on how to install and run a Kivy app at boot on Buster lite:

First install xserver-org, as we need it to show the actual window:

sudo apt-get -y install xserver-xorg

Next I install nodm from source, so it includes the following fix: https://github.com/spanezz/nodm/pull/10:

sudo apt-get -y install libpam0g-dev help2man libx11-dev debhelper
git clone https://github.com/slashblog/nodm.git
pushd nodm
    git checkout d48a8f6266d3f464138e0e95b65896917c35c89f
    source /etc/os-release  # Will set the 'VERSION' variable
    if [ "$(echo $VERSION | sed -En 's/[0-9]+ \(([a-z]+)\)/\1/p')" == "buster" ]; then
        wget http://deb.debian.org/debian/pool/main/n/nodm/nodm_0.13-5.debian.tar.xz
    else
        wget http://deb.debian.org/debian/pool/main/n/nodm/nodm_0.13-1.3.debian.tar.xz
    fi
    tar xf nodm_0.13-*.debian.tar.xz
    sudo dpkg-buildpackage -us -uc -b
popd
sudo dpkg -i nodm_0.13-*_armhf.deb
sudo rm -rf nodm*

Now enable graphical login:

sudo systemctl set-default graphical.target

Configure nodm and start our app at boot:

# Has the same effect as calling 'sudo dpkg-reconfigure nodm'
sudo sh -c 'echo "NODM_ENABLED=true" > /etc/default/nodm'
sudo sh -c 'echo "NODM_USER=$SUDO_USER" >> /etc/default/nodm' # Note that the variable SUDO_USER is used
sudo sh -c 'echo "NODM_FIRST_VT='\''7'\''" >> /etc/default/nodm'
sudo sh -c 'echo "NODM_XSESSION=/etc/X11/Xsession" >> /etc/default/nodm'
sudo sh -c 'echo "NODM_X_OPTIONS='\''-nolisten tcp'\''" >> /etc/default/nodm'
sudo sh -c 'echo "NODM_MIN_SESSION_TIME=60" >> /etc/default/nodm'
sudo sh -c 'echo "NODM_X_TIMEOUT=300" >> /etc/default/nodm'

# Start the app using nodm
echo '#!/bin/bash' > ~/.xsession
echo 'export DISPLAY=:0.0' >> ~/.xsession
echo "~/venv-kivy/bin/python3 ~/app.py" >> ~/.xsession

Setup a virtual enveriment:

sudo apt-get -y install python3-pip python3-venv
sudo pip3 install -U pip
python3 -m venv venv-kivy
source ~/venv-kivy/bin/activate

Install Kivy dependencies:

sudo apt-get -y install python3-dev libmtdev1 libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
sudo apt-get -y install pkg-config libgl1-mesa-dev libgles2-mesa-dev libgstreamer1.0-dev gstreamer1.0-plugins-{bad,base,good,ugly} gstreamer1.0-{omx,alsa} libmtdev-dev
pip3 install -U pygments docutils Cython==0.29.10 wheel

Now it’s time for compiling and installing Kivy. Note that I use my fork with a patch, so it does not use the proprietary Broadcom drivers that are not available on the Raspberry Pi 4 (https://github.com/Lauszus/kivy/commit/9cdcada34a6149b7fd6bd4c57285afc828d69948):

export VIDEOCOREMESA=1; pip3 install git+https://github.com/Lauszus/kivy.git@rpi4_auto#egg=kivy

Finally create a small test app:

cat <<EOF > ~/app.py
from kivy.app import App
from kivy.uix.button import Button


class TestApp(App):

    def build(self):
        return Button(text='hello world')


if __name__ == '__main__':
    TestApp().run()
EOF

Now reboot and enjoy 😃

I encountered failed to add service - already in use? on buster full, when trying to use the egl_rpi backend. Fixing it by commenting out dtoverlay=vc4-kms-v3d in /boot/config.txt made the error go away, but then kivy didn’t show anything at all.

I wonder if it’s the same on buster lite?

@Lauszus

I wasn’t putting the video= parameters on the same line. Wasn’t until you pointed me back to the documentation that I noticed it very explicitly states that all cmdline.txt parameters/configs need to be on one line. Rookie mistake.

Thanks for your help!

Ok, my bad, I forgot to merge https://github.com/kivy/kivy-server/pull/17. Should be fixed now.

For anyone reading this; https://github.com/kivy/kivy/pull/6769 has now been merged, so no changes to Kivy is no longer needed, but you still need to compile SDL2 from source. Instructions can be found in the official docs: https://kivy.org/doc/master/installation/installation-rpi.html.

I never got kivy to work on debian Jessie without a patch either. But if you are okay with using egl, then I have found it useful in the past to patch the initializer in kivy/core/window/window_egl_rpi.py, by replacing:

-    def create_window(self):
+    def create_window(self, *args):

I had similar issues with an older version of kivy a couple of months ago, and this did the trick.

If I remember correctly, creating a window using egl fails by default because extra arguments are passed. The exception is caught somewhere, and ignored.

On Debian Jessie, this patch solved all problems for me, but I have not tested this on Buster.

It could still be that the egl option is ignored due to this commit: 333a4cc9c7b4b3168f7427d27f4fdea2a69bc52b.

Anyway, ymmv.

@Gawezi You need to set kivy to use the egl_rpi window, not x11 by setting KIVY_WINDOW=egl_rpi. If you did mean to run x11, then make sure to compile kivy with x11 support at installation time (USE_X11=1).