尝试在pycharm中运行简单的kivy程序时出错

时间:2020-08-21 16:00:08

标签: python kivy python-3.7 kivy-language

我试图运行以下代码:

kivy.require('1.11.1')
from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):
    def build(self):
        return Label(text='Hello world')

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

但是我收到此错误消息:

[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.2.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.2.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.2.0
[INFO   ] [Kivy        ] v2.0.0rc3, git-20c14b2, 20200615
[INFO   ] [Kivy        ] Installed at "C:\Users\Emmy\kivy_venv\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 16:30:00) [MSC v.1900 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\Emmy\kivy_venv\Scripts\python.exe"
[INFO   ] [Factory     ] 185 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_pil (img_sdl2, img_ffpyplayer, img_gif ignored)
[INFO   ] [Text        ] Provider: pil(['text_sdl2'] 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
sdl2 - ImportError: DLL load failed: Det går inte att hitta den angivna modulen.
  File "C:\Users\Emmy\kivy_venv\lib\site-packages\kivy\core\__init__.py", line 62, in core_select_lib
    fromlist=[modulename], level=0)
  File "C:\Users\Emmy\kivy_venv\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.

我正在使用pycharm并已安装:Kivy,kivy-deps.glew,kivy-deps.gstreamer,kivy-deps.sdl2,pygame和枕头。

我正在使用python 3.7

1 个答案:

答案 0 :(得分:0)

已经出现此错误,在我更新pycharm并仅为Kivy创建了新环境后,该错误起作用了。

https://imgur.com/oszZxVa

您还需要导入kivy才能使用require。

import kivy
from kivy.app import App
from kivy.uix.label import Label

kivy.require('1.11.1')


class MyApp(App):
    def build(self):
        return Label(text='Hello world')


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