无法在奇异果中打开窗口

时间:2018-10-23 13:15:55

标签: python kivy

我开始在游戏中使用kivy,因此在在线学习一些教程时,python shell返回这些错误。

[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.

我已经安装了docutils,pygments,pypiwin32,kivy.deps.sdl2,kivy.deps.glew和Cython。我正在使用kivy 1.10.1和python 3.7.0 我遵循的代码是这样的:

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

我的模块有错误还是代码有问题?

3 个答案:

答案 0 :(得分:1)

代码对我来说很好。您似乎缺少一些依赖项。

您已经列出了我可以看到的所有必需的依赖项,但是也许它们没有正确安装:

看这个答案或下面的答案以获得一些建议:

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

使用pip进行安装对某些用户有效:

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

否则,他们需要卸载并重新安装或使用conda。

答案 1 :(得分:1)

看看Kivy's install Docs,我能够从全新安装中重复您的问题,在该安装中,我没有先进行依赖就安装了kivy。

我通过依次运行这些命令来修复它:

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

在运行Python 3时,您还需要:

python -m pip install kivy.deps.angle

注意:如果您正在使用python2和python3运行环境-请确保将pip替换为pip3

答案 2 :(得分:-1)

尝试安装教程网站上列出的所有依赖项!它列出了运行kivy应用可能需要的所有模块。