0

无法使用 Kivy 11.1.1 在 Raspberry4 (Buster) 上的 systemd 中启动 Kivy 应用程序。

我使用在 Raspberry4 (buster) 上运行的 Kivy 框架 11.1 编写了一个应用程序。当我从 cli 启动应用程序时,它运行良好

但是,在 systemd 中启动同一个应用程序时出现错误。看起来环境变量设置不正确。下面是一个插图 - 仅供参考,我在导入 kivy 之前在我的程序中添加了 os.system('env') 。

LANGUAGE=fr_FR.UTF-8
USER=asysclay
SHLVL=0
HOME=/home/asysclay
OLDPWD=/
PS1=(ENV) 
LOGNAME=asysclay
JOURNAL_STREAM=8:52735
_=/home/asysclay/ASYSClay/ENV/bin/python
PATH=/home/asysclay/ASYSClay/ENV/bin:/home/asysclay/ASYSClay/ENV/bin:/home/asysclay/ASYSClay/asysclayscores/sbin:/bin:/usr/sbin:/usr/bin
INVOCATION_ID=f86a4183f7b840ff88e9aac0fe41c9ef
KIVY_WINDOW=sdl2
LANG=fr_FR.UTF-8
SHELL=/bin/bash
VIRTUAL_ENV=/home/asysclay/ASYSClay/ENV
PWD=/home/asysclay/ASYSClay/asysclayscores

[INFO   ] [Logger      ] Record log in /home/asysclay/.kivy/logs/kivy_19-09-06_79.txt
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "/home/asysclay/ASYSClay/ENV/local/lib/python2.7/site-packages/kivy/__init__.pyc"
[INFO   ] [Python      ] v2.7.16 (default, Apr  6 2019, 01:42:57) 
[GCC 8.2.0]
[INFO   ] [Python      ] Interpreter at "/home/asysclay/ASYSClay/ENV/bin/python"
[WARNING] [Deprecated  ] Python 2 Kivy support has been deprecated. The Kivy release after 1.11.0 will not support Python 2 anymore
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
error: XDG_RUNTIME_DIR not set in the environment.
[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 pot
ential causes
sdl2 - RuntimeError: Could not initialize EGL
  File "/home/asysclay/ASYSClay/ENV/local/lib/python2.7/site-packages/kivy/core/__init__.py", line 71, in core_select_lib
    cls = cls()
  File "/home/asysclay/ASYSClay/ENV/local/lib/python2.7/site-packages/kivy/core/window/window_sdl2.py", line 152, in __init__
    super(WindowSDL, self).__init__()
  File "/home/asysclay/ASYSClay/ENV/local/lib/python2.7/site-packages/kivy/core/window/__init__.py", line 981, in __init__
    self.create_window()
  File "/home/asysclay/ASYSClay/ENV/local/lib/python2.7/site-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
4

1 回答 1

0

我在尝试使用 systemd 服务文件自动启动 Kivy 应用程序时遇到了同样的问题。我得到的错误是

Loaded: loaded (/etc/systemd/system/wfpiconsole.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2019-09-22 15:11:26 BST; 1min 34s ago
Process: 448 ExecStart=/usr/bin/python3 -u main.py (code=exited, status=1/FAILURE)
Main PID: 448 (code=exited, status=1/FAILURE)

Sep 22 15:11:24 raspberrypi python3[448]:     self.create_window()
Sep 22 15:11:24 raspberrypi python3[448]:   File "/usr/local/lib/python3.7/dist-packages/kivy/core/window/window_sdl2.py", lin
Sep 22 15:11:24 raspberrypi python3[448]:     self.get_gl_backend_name())
Sep 22 15:11:24 raspberrypi python3[448]:   File "kivy/core/window/_window_sdl2.pyx", line 224, in kivy.core.window._window_sd
Sep 22 15:11:24 raspberrypi python3[448]:   File "kivy/core/window/_window_sdl2.pyx", line 74, in kivy.core.window._window_sdl
Sep 22 15:11:25 raspberrypi python3[448]: [INFO   ] [Text        ] Provider: sdl2
Sep 22 15:11:25 raspberrypi python3[448]: 2019-09-22 15:11:25+0100 [-] Log opened.
Sep 22 15:11:26 raspberrypi python3[448]: [CRITICAL] [App         ] Unable to get a Window, abort.
Sep 22 15:11:26 raspberrypi systemd[1]: wfpiconsole.service: Main process exited, code=exited, status=1/FAILURE
Sep 22 15:11:26 raspberrypi systemd[1]: wfpiconsole.service: Failed with result 'exit-code'.

我通过添加Environment=DISPLAY=:0[Service]systemd 文件的部分解决了这个问题。

于 2019-09-22T14:53:05.830 回答