You are not logged in.

#1 2009-01-21 15:49:44

tsv
Member
From: UK
Registered: 2008-12-03
Posts: 71
Website

PyGTK - 'module' has no attribute 'require'

Hi guys,

I'm new to both Python and PyGTK, just writing a Hello World program in PyGTK and I'm getting the following error:

Traceback (most recent call last):
  File "./pygtk.py", line 3, in <module>
    import pygtk
  File "/home/dave/chirrup/pygtk.py", line 4, in <module>
    pygtk.require('2.0')
AttributeError: 'module' object has no attribute 'require'

It's choking on:

pygtk.require('2.0')

It works when i remove the offending line, but what exactly is wrong with this line? It's in every PyGTK demonstration I've seen, and Googling this error has only confused me.

Help really appreciated, cheers!

Offline

#2 2009-01-21 15:52:44

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: PyGTK - 'module' has no attribute 'require'

?

In [1]: import pygtk

In [2]: pygtk.
pygtk.__all__                  pygtk.__file__                 pygtk.__new__                  pygtk.__sizeof__               pygtk._pygtk_dir_pat           pygtk.require20
pygtk.__builtins__             pygtk.__format__               pygtk.__package__              pygtk.__str__                  pygtk._pygtk_required_version  pygtk.sys
pygtk.__class__                pygtk.__getattribute__         pygtk.__reduce__               pygtk.__subclasshook__         pygtk.fnmatch                  
pygtk.__delattr__              pygtk.__hash__                 pygtk.__reduce_ex__            pygtk._get_available_versions  pygtk.glob                     
pygtk.__dict__                 pygtk.__init__                 pygtk.__repr__                 pygtk._our_dir                 pygtk.os                       
pygtk.__doc__                  pygtk.__name__                 pygtk.__setattr__              pygtk._pygtk_2_0_dir           pygtk.require                  

In [2]: pygtk.re
pygtk.require    pygtk.require20  

In [2]: pygtk.require
Out[2]: <function require at 0xe98c80>

Cthulhu For President!

Offline

#3 2009-01-21 15:54:42

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: PyGTK - 'module' has no attribute 'require'

OH I see.  Look, it's not importing the right pygtk.  You have a file called pygtk.py higher up the path..."/home/dave/chirrup/pygtk.py"


Cthulhu For President!

Offline

#4 2009-01-21 15:59:44

tsv
Member
From: UK
Registered: 2008-12-03
Posts: 71
Website

Re: PyGTK - 'module' has no attribute 'require'

Oh, hell, that was one stupid mistake.

Apparently naming your files the same as the ones you're trying to import isn't big or clever...

*shamed*

Cheers for the help!

Offline

#5 2009-01-21 16:21:46

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: PyGTK - 'module' has no attribute 'require'

tsv wrote:

Oh, hell, that was one stupid mistake.

Apparently naming your files the same as the ones you're trying to import isn't big or clever...

The new relative/absolute import syntax is designed to overcome this problem:

http://www.python.org/dev/peps/pep-0328/

Renaming the module is probably smartest in your case, but its something to be aware of. :-)

Dusty

Offline

Board footer

Powered by FluxBB