无法在 Ubuntu Python 2.7 中导入 GTK
我尝试在 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'
如何解决此问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是空闲时的错误。查看该错误消息的最后一行:
这表明 warning.idle_showwarning 方法没有参数“file”。
果然查看 /usr/lib/python2.7/warnings.py
没有这个说法。
这显然已在源代码管理中得到解决,但我认为它尚未发布。我只需破解 /usr/lib/python2.7/idlelib/PyShell.py 文件并从第 64 行删除有问题的参数。
然后再试一次......
This is a bug in idle. Looking at the last line of that error message:
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
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...
在 IDLE 之外尝试一下。这里的错误是在 IDLE 中,而不是您的代码。
创建一个包含
import gtk
的新脚本并将其保存在任何位置。在命令行中,在脚本所在的目录中运行
pythonwhatever_your_scripts_name_is.py
。看看是否有错误。您可能无法在 IDLE 中
导入 gtk
。编辑:在某些情况下,显然存在 GTK 和 IDLE 的问题乌班图。
尝试不同的 Python shell;我推荐 IPython,您可以使用 Synaptic 或
sudo apt-get install ipython
安装它。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
.