我尝试在 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/