简体   繁体   中英

Kivy fails to run a basic window

I'm trying to run this code:

import kivy
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()

but I get the error below all the time, i tried to re-install Kivy and Python...

[INFO   ] [Logger      ] Record log in C:\Users\gabi\.kivy\logs\kivy_21-12-22_45.txt
[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\gabi\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\gabi\PycharmProjects\kivy_1\venv\Scripts\python.exe"
[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)
[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\gabi\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\gabi\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

I'm running python 3.9.9 with PyCharm.

One of my friends have same problem it's very easy to solve, in windows just run cmd and type the following commnands to completely delete kivy:

pip uninstall Kivy kivy.deps.angle kivy.deps.glew kivy.deps.sdl2

then type pip freeze and check if there still any packages start with kivy delete it using pip uninstall [package-name] then run cmd as administrator and type the following command:

pip install kivy[base]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM