seth
seth

Reputation: 701

Problems loading pygtk on Ubuntu 11.04

I'm trying to use pygtk in Python but when I try running my code I get this error:

Traceback (most recent call last):
  File "application.py", line 3, in <module>
    pygtk.require(2.0)
  File "/usr/lib/python2.7/dist-packages/pygtk.py", line 85, in require
    "required version '%s' not found on system" % version
AssertionError: required version '2.0' not found on system

Here is the code I'm trying to run (it's basically the Hello World example from the pygtk website):

#!/usr/bin/env python
import pygtk
pygtk.require(2.0)
import gtk

class Application():
  def hello(self, widget, data=None):
    print 'Hello World'

  def delete_event(self, widget, event, data=None):
    print 'delete even occurred'
    return False

  def destroy(self, widget, data=None):
    gtk.main_quit()

  def __init__(self):
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.connect('delete_event', self.delete_event)
    self.quitButton = Button(self, text='Quit', command=self.quit)
    self.quitButton.grid()
    self.window.set_border_width(10)
    self.button = gtk.Button('Hello World')
    self.button.connect('clicked', self.hello, None)
    self.button.connect_object('clicked', gtk.Widget.destroy, self.window)
    self.window.add(self.button)
    self.button.show()

  def main(self):
    gtk.main()

def main():
  app = Application()
  app.main()

if __name__ == '__main__':
  main()

Also, when I try running pygtk-demo everything works ok, even though it is importing the library the same way that I am. Also it outputs PyGTK Demo (gtk: v2.24.4, pygtk: v2.22.0) so you can see that I have a version that is >2.0.

Upvotes: 0

Views: 387

Answers (1)

mechanical_meat
mechanical_meat

Reputation: 169274

The 3rd line in your file should read:

pygtk.require('2.0')

Because 2.0 is a string in this case, not a float.

Upvotes: 1

Related Questions