You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Kivy 2.0.0与Python 3.9运行代码报错:无法找到可用Window提供者

IntelliJ运行Kivy代码报无法找到Window provider错误

我在IntelliJ中运行任何自行编写的Kivy代码时都会出现相同报错,当前使用的版本为Kivy 2.0.0、Python 3.9。

我的代码如下:

from kivy.app import App
from kivy.lang import Builder

kv = """
Screen:
    FloatLayout:
        Button:
            text: "It works!"
            pos_hint: {"x": 0.1, "y": 0.7}
            text_size: self.size
        """


class MyApp(App):
    def build(self):
        self.screen = Builder.load_string(kv)
        return self.screen


if __name__ == "__main__":
    MyApp().run()

我已经尝试过多种解决方案,包括重新安装Kivy、添加至环境变量路径、安装全部依赖项,均未能解决问题。报错信息如下:

[INFO   ] [Logger      ] Record log in C:\Users\James\.kivy\logs\kivy_21-10-25_21.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.3.2
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "C:\Users\james\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\james\IdeaProjects\HelloWorld\venv\Scripts\python.exe"
[INFO   ] [Logger      ] Purge log fired. Analysing...
[INFO   ] [Logger      ] Purge 9 log files
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pil (img_sdl2, img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: pil(['text_sdl2'] ignored)
2.0.0
[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 - ImportError: DLL load failed while importing _window_sdl2: The specified module could not be found.
  File "C:\Users\james\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\core\__init__.py", line 58, in core_select_lib
    mod = __import__(name='{2}.{0}.{1}'.format(
  File "C:\Users\james\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\core\window\window_sdl2.py", line 27, in <module>
    from kivy.core.window._window_sdl2 import _WindowSDL2Storage

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

Process finished with exit code 1

编辑补充

感谢Weebify的帮助问题已解决,解决方法为严格遵循Kivy官方文档的下载指引操作,我已将本人使用的完整解决步骤发布为回答(暂未被标记为最佳答案)。

内容的提问来源于stack exchange,提问作者Raed Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 15:39:02