Cannot get window to open in kivy [duplicate]

纵然是瞬间 提交于 2020-01-06 05:14:27

问题


I am starting to use kivy for my game, so while following some tutorials online, the python shell returns these errors.

[INFO] [Logger] Record log in C:\Users\chi_j\.kivy\logs\kivy_18-10-23_8.txt
[INFO] [Kivy] v1.10.1
[INFO] [Python] v3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)]
[INFO] [Factory] 194 symbols loaded
[INFO] [Image] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO] [Window] Provider: sdl2
[CRITICAL] [Window] Unable to find any valuable Window provider.
sdl2 - ImportError: DLL load failed: The specified module could not be found.
  File "C:\Users\chi_j\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\__init__.py", line 67, in core_select_lib
    cls = cls()
  File "C:\Users\chi_j\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 140, in __init__
    super(WindowSDL, self).__init__()
  File "C:\Users\chi_j\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\window\__init__.py", line 968, in __init__
    self.create_window()
  File "C:\Users\chi_j\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\core\window\window_sdl2.py", line 272, in create_window
    self.fullscreen, resizable, state)
  File "kivy\core\window\_window_sdl2.pyx", line 125, in kivy.core.window._window_sdl2._WindowSDL2Storage.setup_window
  File "kivy\graphics\cgl.pyx", line 52, in kivy.graphics.cgl.cgl_get_backend_name
  File "kivy\graphics\cgl.pyx", line 60, in kivy.graphics.cgl.cgl_get_backend_name
  File "C:\Users\chi_j\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  [CRITICAL] [App] Unable to get a Window, abort.

I have installed docutils, pygments, pypiwin32, kivy.deps.sdl2, kivy.deps.glew and Cython. I am using kivy 1.10.1 and python 3.7.0 The code that I was following is this:

from kivy.app import App
from kivy.uix.widget import Widget


class PongGame(Widget):
    pass


class PongApp(App):
    def build(self):
        return PongGame()


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

Am I having errors with my modules or something wrong with the code?


回答1:


Looking at Kivy's install Docs I was able to repeat your problem from a fresh install, where I installed kivy without first doing the dependancies.

I fixed it by running these in order:

python -m pip install --upgrade pip wheel setuptools

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew

python -m pip install kivy.deps.gstreamer

python -m pip install kivy

As you're running Python 3 you'll also need:

python -m pip install kivy.deps.angle

Note: If you're running an environment with python2 and python3 - make sure you replace pip with pip3




回答2:


The code runs fine for me. It looks likely that you are missing some dependencies.

You have listed all the required dependencies I can see, but perhaps they have not been installed properly:

Looking at this answer or the one below it for some suggestions:

https://stackoverflow.com/a/44220712/9742036

Installing using pip worked for some users:

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew; python -m pip install kivy.deps.gstreamer

Otherwise they needed to uninstall and re-install or use conda.



来源:https://stackoverflow.com/questions/52950076/cannot-get-window-to-open-in-kivy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!