我从kivy开始。这是我正在运行的示例代码。
import kivy
from kivy.app import App
from kivy.uix.button import Label
kivy.require('1.9.0')
class HelloApp(App):
def build(self):
return Label(text='Hello World!')
if __name__ == "__main__":
HelloApp().run()
这是我得到的追溯:
[INFO ] [Logger ] Record log in C:Usersmonac.kivylogskivy_16-11-23_9.txt
[INFO ] [Kivy ] v1.9.1
[INFO ] [Python ] v3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
[INFO ] [Factory ] 179 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <b'4.5.0 NVIDIA 373.06'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'GeForce GTX 960M/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <b'4.50 NVIDIA'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[WARNING ] [Image ] Unable to load image <C:Python34libsite-packageskivydataglsldefault.png>
[CRITICAL ] [Window ] Unable to find any valuable Window provider at all!
sdl2 - Exception: SDL2: Unable to load image
File "C:Python34libsite-packageskivycore__init__.py", line 67, in core_select_lib
cls = cls()
File "C:Python34libsite-packageskivycorewindowwindow_sdl2.py", line 138, in __init__
super(WindowSDL, self).__init__()
File "C:Python34libsite-packageskivycorewindow__init__.py", line 722, in __init__
self.create_window()
File "C:Python34libsite-packageskivycorewindowwindow_sdl2.py", line 255, in create_window
super(WindowSDL, self).create_window()
File "C:Python34libsite-packageskivycorewindow__init__.py", line 897, in create_window
self.render_context = RenderContext()
File "kivygraphicsinstructions.pyx", line 756, in kivy.graphics.instructions.RenderContext.__init__ (kivygraphicsinstructions.c:10729)
File "C:Python34libsite-packageskivycoreimage__init__.py", line 512, in __init__
self.filename = arg
File "C:Python34libsite-packageskivycoreimage__init__.py", line 700, in _set_filename
mipmap=self._mipmap, nocache=self._nocache)
File "C:Python34libsite-packageskivycoreimage__init__.py", line 430, in load
im = loader(filename, **kwargs)
File "C:Python34libsite-packageskivycoreimage__init__.py", line 198, in __init__
self._data = self.load(filename)
File "C:Python34libsite-packageskivycoreimageimg_sdl2.py", line 42, in load
raise Exception('SDL2: Unable to load image')
[CRITICAL ] [App ] Unable to get a Window, abort.
Exception ignored in: 'kivy.properties.dpi2px'
Traceback (most recent call last):
File "C:Python34libsite-packageskivyutils.py", line 513, in __get__
retval = self.func(inst)
File "C:Python34libsite-packageskivymetrics.py", line 175, in dpi
EventLoop.ensure_window()
File "C:Python34libsite-packageskivybase.py", line 126, in ensure_window
sys.exit(1)
SystemExit: 1
[CRITICAL ] [App ] Unable to get a Window, abort.
我在Windows 10 64bits上运行。我已经安装了除gstreamer
以外的所有依赖项,目前我不需要。
我也不确定为什么会遇到此错误:
[WARNING ] [Image ] Unable to load image <C:Python34libsite-packageskivydataglsldefault.png>
文件存在,我正在运行代码作为管理员,以避免访问权限问题。
谢谢。
您必须安装Kivy的依赖项。
按照此处的说明
python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
将做您需要的事情。
我在使用--system-site-packages
创建我的VirtualEnv之前,安装Kivy及其依赖项后,遇到了相同的错误。为了解决它,我必须离开我的虚拟,卸载所有包装kivy,输入我的Virtualenv,然后重新安装。
您必须安装所有依赖项详细检查此URLhttps://kivy.org/docs/installation/installation-windows.html#kivy-dependencies我逐步遵循不要忘记安装kivy.deps.angle,kivy.deps.glew,kivy.deps.gstreamer,kivy.deps.sdl2
在虚拟软件的显示设置(aka vmbox,vmware)中禁用3D加速度和2D视频加速度。我认为这对您有用,经过很多尝试,它对我有用。
使用pyinstaller生成的区域时,有些人可能遇到相同的问题。
Kivy Doc提醒开发人员添加这些依赖项。https://kivy.org/doc/stable/guide/packaging-windows.html#pyinstaller-default-hook
但是我不得不添加 Angle 使其在我的上下文中起作用。
from kivy_deps import sdl2, glew, angle
coll = COLLECT(exe, Tree('examples-path\demo\touchtracer\'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins+ angle.dep_bins)],
strip=False,
upx=True,
name='touchtracer')