Kivy的Hello World无法运行

5 投票
2 回答
3828 浏览
提问于 2025-04-17 18:19

我正在尝试在我的Ubuntu系统上运行kivy。为了做到这一点,我按照他们网站上的说明进行了操作,网址是这里

但是,当我尝试运行他们网站上的以下“你好,世界”代码时:

import kivy
kivy.require('1.5.1') # replace with your current kivy version !

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

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

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

我遇到了以下错误:

[INFO   ] Kivy v1.5.1
[INFO   ] [Logger      ] Record log in /home/malik/.kivy/logs/kivy_13-03-08_6.txt
[INFO   ] [Factory     ] 137 symbols loaded
[DEBUG  ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG  ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG  ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[DEBUG  ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG  ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[INFO   ] [Text        ] using <pygame> as text provider
[DEBUG  ] [App         ] Loading kv <./my.kv>
[DEBUG  ] [App         ] kv <./my.kv> not found
[INFO   ] [Window      ] using <pygame> as window provider
  X Error of failed request:  BadRequest (invalid request code or no such operation)
    Major opcode of failed request:  138 (ATIFGLEXTENSION)
    Minor opcode of failed request:  66 ()
    Serial number of failed request:  14
    Current serial number in output stream:  14

这和我的显卡有关吗?我使用的是ATI Mobility Radeon HD 5400显卡。

2 个回答

3

我按照你提供的说明进行了操作,并使用了你给的代码,得到了这个结果。请看这个图 figure1。我用的Python版本是python2.7,系统是ubuntu12.10。

这段代码需要超级用户权限,所以我是在命令行中运行的:sudo python demo.py

试着用'sudo'来运行它。

5

最后通过把Ubuntu更新到12.10解决了问题。看起来问题出在显卡驱动上。现在这个例子运行得很正常。谢谢Qiongjie和qua-non的帮助。

撰写回答