Python Kivy不会使用SDL2,坚持使用pygame

问题描述 投票:0回答:1

我努力使Kivy(1.11.0)在Ubuntu 18.04桌面上使用SDL2。它一直要求pygame,但是已经过时了,我不想将其用于新项目。

在全新的Ubuntu 18.04 VM上,这就是我所做的:

~ $ sudo apt install libsdl2-dev libsdl2-image-dev mesa-common-dev python3-pip python3-venv
~ $ pip3 install --user poetry
~ $ poetry new kivytest
~ $ cd kivytest

~/kivytest $ poetry add kivy pillow
Creating virtualenv kivytest-sUhjZQq9-py3.6 in ~/.cache/pypoetry/virtualenvs
Using version ^1.11.1 for kivy
Using version ^7.0.0 for pillow

Updating dependencies
Resolving dependencies... (2.2s)

Writing lock file


Package operations: 20 installs, 0 updates, 0 removals

  - Installing certifi (2019.11.28)
  - [...]
  - Installing pillow (7.0.0)
  - Installing kivy (1.11.1)

安装了kivy后,我创建了一个简单的test.py文件:

from kivy.app import App
from kivy.uix.button import Button

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

TestApp().run()

但是,当我运行它失败时:

~/kivytest $ export KIVY_GL_BACKEND="sdl2"

~/kivytest $ poetry run python3 ./test.py
[INFO   ] [Logger      ] Record log in ~/.kivy/logs/kivy_20-03-29_6.txt
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "~/.cache/pypoetry/virtualenvs/kivytest-sUhjZQq9-py3.6/lib/python3.6/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0]
[INFO   ] [Python      ] Interpreter at "~/.cache/pypoetry/virtualenvs/kivytest-sUhjZQq9-py3.6/bin/python3"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pil, img_gif (img_pygame, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: pil(['text_pygame'] ignored)
[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
egl_rpi - ImportError: cannot import name 'bcm'
  File "~/.cache/pypoetry/virtualenvs/kivytest-sUhjZQq9-py3.6/lib/python3.6/site-packages/kivy/core/__init__.py", line 63, in core_select_lib
    fromlist=[modulename], level=0)
  File ".../kivy/core/window/window_egl_rpi.py", line 12, in <module>
    from kivy.lib.vidcore_lite import bcm, egl

pygame - ModuleNotFoundError: No module named 'pygame'
  File ".../kivy/core/__init__.py", line 63, in core_select_lib
    fromlist=[modulename], level=0)
  File ".../kivy/core/window/window_pygame.py", line 13, in <module>
    import pygame

x11 - ModuleNotFoundError: No module named 'kivy.core.window.window_x11'
  File ".../kivy/core/__init__.py", line 63, in core_select_lib
    fromlist=[modulename], level=0)

[CRITICAL] [App         ] Unable to get a Window, abort.

我如何强制它使用SDL2?我已经安装了系统SDL2库,并安装了kivy after,等等。>>

这是非重复项

,类似的问题,因为我在Ubuntu上运行它而询问Windows或Mac OS-X,并且该解决方案不适用。

谢谢!

我努力使Kivy(1.11.0)在Ubuntu 18.04桌面上使用SDL2。它对pygame的要求很高,但是已经过时了,我不想在新项目中使用它。在全新的Ubuntu 18.04 VM上...

python kivy sdl-2
1个回答
0
投票

[确定,我找到了原因-为了建立支持SDL2的kivy,还需要一些SDL2库。这有效:

© www.soinside.com 2019 - 2024. All rights reserved.