Search code examples
pythonraspberry-pikivy

Kivy can't open a window on Raspberry Pi 4, cites a lack of x11 server even though window provider is SDL2


I've been trying to get Kivy to run on a Raspberry Pi 4 running the latest version of Raspberry OS Bullseye. I started from a clean OS flash, followed the basic instructions for installation linked here. I additionally also installed all of the dependencies it asked me to install for a RasPi as linked here, specifically the instructions for installing with a desktop environment using apt-get. When I try to run any Kivy application the following is spit out, and now window opens.

[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'2.1 Mesa 20.3.5'>
[INFO   ] [GL          ] OpenGL vendor <b'Broadcom'>
[INFO   ] [GL          ] OpenGL renderer <b'V3D 4.2'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 1
[INFO   ] [GL          ] Shading version <b'1.20'>
[INFO   ] [GL          ] Texture max size <4096>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2(['text_pango'] ignored)
Unable to connect to X server
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event4
[INFO   ] [MTD         ] Read event from </dev/input/event4>
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [MTD         ] </dev/input/event4> range position X is 0 - 4096
[INFO   ] [MTD         ] </dev/input/event4> range position Y is 0 - 4096
[INFO   ] [MTD         ] </dev/input/event4> range touch major is 0 - 4096
[INFO   ] [MTD         ] </dev/input/event4> range touch minor is 0 - 0
[INFO   ] [MTD         ] </dev/input/event4> range pressure is 0 - 255
[INFO   ] [MTD         ] </dev/input/event4> axes invertion: X is 0, Y is 0
[INFO   ] [MTD         ] </dev/input/event4> rotation set to 0

I've tried uninstalling and reinstalling all of the relevant packages multiple times, reflashing the pi OS, following the instructions to build SDL2 from source under "raspberry pi 4 headless installation on raspbian buster, and nothing has worked. I don't understand why it's even trying to connect to an X11 server, shouldn't it be using sdl2 by default? I am unable to run any of the demo applications. My installs on both a macOS and Windows machine work fine, the pi is just not working for some reason.


Solution

  • I have the same problem too, I was only able tu run in bullseye with desktop environment and only from the raspberry screen, from a ssh connection I had the same error message.

    In other try I begin in a bullsese 64bits whitout desktop, and install all this dependencies, I don't know if all this are neccesary.

    sudo apt update
    sudo apt install python3-setuptools git-core python3-dev
    sudo apt install pkg-config libgl1-mesa-dev libgles2-mesa-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-0:arm64 gstreamer1.0-alsa libmtdev-dev xclip xsel libjpeg-dev
    sudo apt install libfreetype6-dev libgl1-mesa-dev libgles2-mesa-dev libdrm-dev libgbm-dev libudev-dev libasound2-dev liblzma-dev libjpeg-dev libtiff-dev libwebp-dev git build-essential gir1.2-ibus-1.0 libdbus-1-dev libegl1-mesa-dev libibus-1.0-5 libibus-1.0-dev libice-dev libsm-dev libsndio-dev libwayland-bin libwayland-dev libxi-dev libxinerama-dev libxkbcommon-dev libxrandr-dev libxss-dev libxt-dev libxv-dev x11proto-randr-dev x11proto-scrnsaver-dev x11proto-video-dev x11proto-xinerama-dev
    sudo apt install libsdl2-dev python3-sdl2
    sudo apt install xinit
    sudo apt install python3-pip git
    python3 -m pip install Kivy kivy_examples
    

    then I run the xserver whit

    startx
    

    This command opened a small terminal with a white background and a mouse cursor, from this terminal I was able run kivy example.

    python3 ~/.local/share/kivy-examples/3Drendering/main.py
    

    For this experience I think that kivy 2 is compatible with raspbian bullseye 64 bits, and not need compile or extensive installation proccess, but need fix this issue for execute the Xs without desktop environment.

    Another alternative would be to be able to execute python script whit some argument to open the Xs, but I don't know how or if this is possible.

    P.D.: Years ago I was able to make it work on stretch and jessie with kivy 1 and python2.7, executed it from both raspberry screen and ssh connection and displaying in raspberry screen (Official Touchscreen 7'').