开发者

Cannot Import GTK in Ubuntu Python 2.7

I'm trying to import GTK in Ubuntu Python 2.7, and I get the following error. PyGTK imports just fine. When I import gtk, I get the following error:

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'

How do I fix this?


This is a bug in idle. Looking at the last line of that error message:

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'

This is saying that the warning.idle_showwarning method does not have an argument "file".

Sure enough looking at /usr/lib/python2.7/warnings.py

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

There is no such argument.

This apparently has been resolved in source control but I do not think it has made it into a release yet. I would just hack the /usr/lib/python2.7/idlelib/PyShell.py file and remove the offending argument from line 64.

Then try it again...


Try it outside of IDLE. The error here is in IDLE, not your code.

Create a new script that contains import gtk and save it anywhere.

From the command line, in the directory where your script is located, run python whatever_your_scripts_name_is.py.

See if you get an error. You may not be able to import gtk in IDLE.

Edit: There is apparently a problem with GTK and IDLE in some situations on Ubuntu.

Try a different Python shell; I'd recommend IPython which you can install with Synaptic or sudo apt-get install ipython.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜