Kivy - NotImplementedError:tostring()已被删除

问题描述:

自从iam卡住了这个错误以来它已经过去了几天。正如你可以在日志中看到有最新版本的Kivy和Python,但是我得到了PermissionError和NotImplementedError。我尝试以超级用户身份运行它,但它仍然无法工作,因为我知道它必须没有它。Kivy - NotImplementedError:tostring()已被删除

当我运行它时会出现一个窗口,但它根本不会呈现任何文本,只有一个神器在midle时会消失,当我点击按钮时,其他一切似乎都很好。

from kivy.app import App 
from kivy.uix.button import Button 

class TestApp(App): 
    def build(self): 
     return Button(text='Hello World') 

TestApp().run() 



[INFO    ] [Logger  ] Record log in /home/shalva/.kivy/logs/kivy_17-01-16_7.txt 
[INFO    ] [Kivy  ] v1.9.1 
[INFO    ] [Python  ] v3.6.0 (default, Dec 24 2016, 08:03:08) 
[GCC 6.2.1 20160830] 
[INFO    ] [Factory  ] 179 symbols loaded 
[INFO    ] [Image  ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored) 
[INFO    ] [Text  ] Provider: pil(['text_sdl2'] ignored) 
[INFO    ] [OSC   ] using <multiprocessing> for socket 
[INFO    ] [Window  ] Provider: sdl2(['window_egl_rpi'] ignored) 
[INFO    ] [GL   ] OpenGL version <b'3.0 Mesa 13.0.3'> 
[INFO    ] [GL   ] OpenGL vendor <b'Intel Open Source Technology Center'> 
[INFO    ] [GL   ] OpenGL renderer <b'Mesa DRI Intel(R) Sandybridge Mobile '> 
[INFO    ] [GL   ] OpenGL parsed version: 3, 0 
[INFO    ] [GL   ] Shading version <b'1.30'> 
[INFO    ] [GL   ] Texture max size <8192> 
[INFO    ] [GL   ] Texture max units <16> 
[INFO    ] [Window  ] auto add sdl2 input provider 
[INFO    ] [Window  ] virtual keyboard not allowed, single mode, not docked 
[INFO    ] [ProbeSysfs ] device match: /dev/input/event6 
[INFO    ] [MTD   ] Read event from </dev/input/event6> 
[INFO    ] [Base  ] Start application main loop 
[INFO    ] [GL   ] NPOT texture support is available 
Exception in thread Thread-1: 
Traceback (most recent call last): 
    File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner 
    self.run() 
    File "/usr/lib/python3.6/threading.py", line 864, in run 
    self._target(*self._args, **self._kwargs) 
    File "/usr/lib/python3.6/site-packages/kivy/input/providers/mtdev.py", line 219, in _thread_run 
    _device = Device(_fn) 
    File "/usr/lib/python3.6/site-packages/kivy/lib/mtdev.py", line 131, in __init__ 
    self._fd = os.open(filename, os.O_NONBLOCK | os.O_RDONLY) 
PermissionError: [Errno 13] Permission denied: '/dev/input/event6' 

Exception ignored in: 'kivy.graphics.instructions.RenderContext.set_texture' 
Traceback (most recent call last): 
    File "kivy/graphics/texture.pyx", line 786, in kivy.graphics.texture.Texture.bind (kivy/graphics/texture.c:10206) 
    File "/usr/lib/python3.6/site-packages/kivy/core/text/__init__.py", line 628, in _texture_fill 
    self.render(real=True) 
    File "/usr/lib/python3.6/site-packages/kivy/core/text/__init__.py", line 573, in render 
    return self._render_real() 
    File "/usr/lib/python3.6/site-packages/kivy/core/text/__init__.py", line 559, in _render_real 
    data = self._render_end() 
    File "/usr/lib/python3.6/site-packages/kivy/core/text/text_pil.py", line 57, in _render_end 
    self._pil_im.mode.lower(), self._pil_im.tostring()) 
    File "/usr/lib/python3.6/site-packages/PIL/Image.py", line 697, in tostring 
    "Please call tobytes() instead.") 
NotImplementedError: tostring() has been removed. Please call tobytes() instead. 
[INFO    ] [Base  ] Leaving application in progress... 

我不确定PermissionError,但我可以帮助解决NotImplementedError。这可能反过来解决PermissionError。

您正在使用Python模块PIL,它曾经有一个函数tostring(),但它已改为tobytes()。但是,kivy软件包尚未更新,因此它仍然会调用tostring(),这已被弃用。

所以,去

/usr/lib/python3.6/site-packages/kivy/core/text/text_pil.py

你的机器和更改线路57从

self._pil_im.mode.lower(), self._pil_im.tostring()) 

self._pil_im.mode.lower(), self._pil_im.tobytes()) 

这应该可以解决你的问题。

当您尝试编辑该文件时,可能会说您没有编辑它们所需的权限。如果是这样,那么我建议在命令行(或终端/任何bash控制台)sudo idle中输入。然后,从空闲状态打开文件并进行编辑。 (注意,无论如何,您可以用sudo(例如sudo nano等)编辑它)。

+0

谢谢,文本呈现。我仍然得到PermissionError,但它似乎没有任何作用...最后的Kivy发布是在1年前,并在Github上,他们有很多活动,为什么他们不发布新版本? –

+0

@GeorgeShalvashvili,我不确定。它可能是它被设计用于和旧版本的PIL(befrore'tostring'被删除)。或者你不知道最近的版本......?我不会为此担心。如果你愿意,可以在Kivy的开发者看到的地方发布这个修补程序(链接到这个页面,如果你喜欢的话)(也许Github?),他们可能会解释为什么它不能直接使用。 – tburrows13

+0

如果这解决了您的错误,请点击upvote/downvote符号下方的勾号将其标记为“已回答”。 – tburrows13