#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Location
    UK (North East England)
    Posts
    9
    Rep Power
    0

    Lightbulb pyGTK Not working on beginners script


    Hi guys

    New to the forum - go easy on me I'm a complete noob

    After going through the motions of pip->easy_install->pip->wheel->pip->easy_install () I eventually got pyGTK installed as a module through cmd line (windows 7 dos)

    I've tried running the first script on the introduction tutorial and hit an error. The following is a grab of the CLI

    Code:
    C:\Python27>easy_install -U pygtk
    Searching for pygtk
    Reading https://pypi.python.org/simple/pygtk/
    Reading http://ftp.acc.umu.se/pub/gnome/binaries/win32/pygtk/2.24/
    Reading http://www.daa.com.au/~james/pygtk/
    Reading http://www.daa.com.au/~james/software/pygtk/
    Reading http://www.pygtk.org
    Reading http://www.pygtk.org/
    Best match: pygtk 2.24.0
    Processing pygtk-2.24.0-py2.7-win32.egg
    pygtk 2.24.0 is already the active version in easy-install.pth
    Installing pygtk_postinstall.py script to C:\Python27\Scripts
    Installing pygtk_postinstall.pyc script to C:\Python27\Scripts
    
    Using c:\python27\lib\site-packages\pygtk-2.24.0-py2.7-win32.egg
    Processing dependencies for pygtk
    Finished processing dependencies for pygtk
    I then create this script

    Code:
    #!/usr/bin/env python
    
    # example base.py
    
    import pygtk
    
    pygtk.require('2.0')
    import gtk
    
    class Base:
       def __init__(self):
          self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
          self.window.show()
    
    def main(self):
       gtk.main()
       
       print __name__
       if __name__ == "__main__":
          base = Base()
          base.main()
    Which then produces the error:

    Code:
    [evaluate pygtk_1.py]
    Traceback (most recent call last):
      File "C:\Users\CMDEV\Desktop\Py\pygtk_1.py", line 5, in <module>
        import pygtk
    ImportError: No module named pygtk
    So my DOS window shows "Finished processing dependencies for pygtk" and "No module named pygtk" which is a perfect definition of contradiction

    Can anyone see what I've done wrong?

    Many thanks
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,787
    Rep Power
    508
    Can you import other libraries? Does
    >>> import re
    work?

    I think something's wrong with your installation, as in PYTHONPATH is set incorrectly in your environment. Try this although it's been a few years since I used python on a windows system.
    Code:
    #!c:\python27\python
    
    # example base.py
    
    import sys
    sys.path.extend((r'c:\python27\lib', r'c:\python27\lib\site-packages',))
    
    import pygtk
    
    pygtk.require('2.0')
    import gtk
    
    class Base:
       def __init__(self):
          self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
          self.window.show()
    
    def main(self):
       gtk.main()
       
       print __name__
       if __name__ == "__main__":
          base = Base()
          base.main()
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Location
    UK (North East England)
    Posts
    9
    Rep Power
    0
    Thanks b49P23Tlvg

    It took over 24 hours before this post showed so this problem doesn't exist any more as I've tried other methods.
  6. #4
  7. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Hey Dal1980,

    I'm sorry that you had to wait so long for your post to be approved. As discussed in this thread: My posts don't appear I have upgraded your forum permissions so that hopefully, in the future, our filter will ignore posts by you and they'll go live immediately.

    Thanks for joining! Welcome to Dev Shed

    Comments on this post

    • Dal1980 agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2015
    Location
    UK (North East England)
    Posts
    9
    Rep Power
    0
    Thanks so much! I really appreciate that

IMN logo majestic logo threadwatch logo seochat tools logo