python - 无法在 Ubuntu Python 2.7 中导入 GTK

标签 python ubuntu gtk pygtk python-idle

我尝试在 Ubuntu Python 2.7 中导入 GTK,但出现以下错误。 PyGTK 导入就好了。当我导入 gtk 时,出现以下错误:

Exception in Tkinter callback Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
File "/usr/lib/python2.7/idlelib/MultiCall.py", line 167, in handler
    r = l[i](event)
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1140, in enter_callback
    self.runit()
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1181, in runit
    more = self.interp.runsource(line)
File "/usr/lib/python2.7/idlelib/PyShell.py", line 619, in runsource
    return InteractiveInterpreter.runsource(self, source, filename)
File "/usr/lib/python2.7/code.py", line 87, in runsource
    self.runcode(code)
File "/usr/lib/python2.7/idlelib/PyShell.py", line 759, in runcode
    self.tkconsole.endexecuting()
File "/usr/lib/python2.7/idlelib/PyShell.py", line 940, in endexecuting
    self.showprompt()
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1205, in showprompt
    self.resetoutput()
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1217, in resetoutput
    if self.history:
File "/usr/lib/python2.7/idlelib/PyShell.py", line 64, in idle_showwarning
    lineno, file=file, line=line))
TypeError: idle_formatwarning() got an unexpected keyword argument 'file'

如何解决这个问题?

最佳答案

这是一个bug处于闲置状态。查看该错误消息的最后一行:

File "/usr/lib/python2.7/idlelib/PyShell.py", line 64, in idle_showwarning
    lineno, file=file, line=line))
TypeError: idle_formatwarning() got an unexpected keyword argument 'file'

这表示 warning.idle_showwarning 方法没有参数“file”。

果然查看了/usr/lib/python2.7/warnings.py

def formatwarning(message, category, filename, lineno, line=None)

没有这样的说法。

这显然已在源代码管理中得到解决,但我认为它尚未发布。我只需破解/usr/lib/python2.7/idlelib/PyShell.py 文件并从第 64 行删除有问题的参数。

然后再试一次...

关于python - 无法在 Ubuntu Python 2.7 中导入 GTK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7016625/

相关文章:

c - 如何在不显示的情况下获取最大化窗口的大小?

python - 加载的主题图标的位置在哪里?

python - Django - TypeError at/statements/int() 参数必须是字符串、类似字节的对象或数字,而不是 'AnonymousUser'

linux - keystore "keybased.sock: connect n osuch file or directory"

python - 使用 python 在文本文件中写入字典列表

Ubuntu CLI 批量查找 CP

ubuntu - 在 AWS 上安装 nginx 后禁止 403(不欢迎 nginx 消息)

python - 与 Glade 一起使用时不可见的 Gtk.EntryCompletion 结果

python - 获取 Selenium Python 中 Html 按钮生成的内容

python - 努力理解python包和导入语句