问题描述
我很难让 Kivy (1.11.0) 使用 SDL2 在 Ubuntu 18.04 桌面上.它一直要求 pygame
但这已被弃用,我不想将它用于新项目.
I struggle to make Kivy (1.11.0) use SDL2 on Ubuntu 18.04 desktop. It keeps demanding pygame
but that's been deprecated and I don't want to use it for a new project.
在一个全新的 Ubuntu 18.04 VM 上,这就是我所做的:
On a fresh new Ubuntu 18.04 VM this is what I did:
~ $ 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
文件:
With kivy
installed I create a simple test.py
file:
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello World')
TestApp().run()
但是当我运行它时它失败了:
However when I run it it fails:
~/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 等.
How can I force it to use SDL2? I've got the system SDL2 libs installed, installed kivy
after, etc.
当我在 Ubuntu 和解决方案不适用.
This is not a duplicate of similar questions asking about Windows or Mac OS-X as I'm running it on Ubuntu and the solutions don't apply.
谢谢!
推荐答案
好的,我找到了原因 - 需要更多的 SDL2 库才能构建支持 SDL2 的 kivy
.这有效:
Ok, I found the reason - a few more SDL2 libraries are required in order to build kivy
with SDL2 support. This works:
~ $ sudo apt install mesa-common-dev
libsdl2-dev libsdl2-image-dev
libsdl2-ttf-dev libsdl2-mixer-dev
然后删除并重新安装 kivy
以使用 SDL2 支持重建它:
And then remove and reinstall kivy
to get it rebuilt with SDL2 support:
~/testkivy $ poetry remove kivy && poetry add kivy
如果你不使用poetry
,也可以使用pip
:
Or with pip
if you don't use poetry
:
(testkivy-venv) ~ $ pip uninstall kivy && pip install --user kivy
然后就可以了:
$ ./test.py
...
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2(['text_pango'] ignored)
[INFO ] [Window ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] Backend used <sdl2> <<<< YAY!!!
[INFO ] [GL ] OpenGL version <b'3.0 Mesa 19.2.8'>
[INFO ] [GL ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO ] [GL ] OpenGL renderer <b'Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2) '>
[INFO ] [GL ] OpenGL parsed version: 3, 0
[INFO ] [GL ] Shading version <b'1.30'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
...
这篇关于Python Kivy 不会使用 SDL2,坚持使用 pygame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!