Pyglet on Python3.x, problems

Discussion in 'Python' started by John Ladasky, Jul 29, 2013.

  1. John Ladasky

    John Ladasky Guest

    Hi folks,

    For whatever reason, the pyglet package is getting a lot of attention on c.l.python these past few days. I am guilty of generating some of that potentially off-topic conversation myself. At the end of my last thread, I reported that I had found the pyglet-users newsgroup, and would direct my questions there.

    https://groups.google.com/d/msg/comp.lang.python/ARtI0GC9RHc/_6URRrhz7nUJ

    Well, I joined pyglet-users. I have waited for about 36 hours for the moderator to approve my first post asking for help. Several other posts have appeared, but not mine. I don't think that I was impolite.

    Apologies to everyone, but I'm going to ask my questions here. As you may recall, I'm teaching some adolescent computer programming students. I needa Python 3-compatible GUI, preferably one oriented towards games. I mighthave that GUI in hand, but I need to test it myself first. I've been researching this issue for over a week. I have a student tomorrow, so I'm facing a bit of a deadline. (Yeah, I could teach him about B-trees instead, but... you know, kids.)

    In my own defense, I'm not entirely certain that the problems I have encountered are specific to pyglet. They might have to do with the limitations of the 2to3 program.

    I'm starting with my own Ubuntu 13.04 system. I downloaded pyglet-1.2alpha1, unzipped it and executed "sudo python3 setup.py install", as I have donewith many a package. Then I tried running various programs in two directories (these programs are also on the pyglet.org web site).

    pyglet-1.2alpha1/examples/programming_guide/hello_world.py runs fine.

    pyglet-1.2alpha1/examples/programming_guide/image_viewer.py also runs fine.

    pyglet-1.2alpha1/examples/programming_guide/animation.py produces an error.Here's the traceback.

    =======================================================

    Traceback (most recent call last):
    File "/usr/local/lib/python3.3/dist-packages/pyglet/resource.py", line 538, in animation
    identity = self._cached_animations[name]
    File "/usr/lib/python3.3/weakref.py", line 69, in __getitem__
    o = self.data[key]()
    KeyError: 'dinosaur.gif'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "animation.py", line 62, in <module>
    animation = pyglet.resource.animation('dinosaur.gif')
    File "/usr/local/lib/python3.3/dist-packages/pyglet/resource.py", line 540, in animation
    animation = pyglet.image.load_animation(name, self.file(name))
    File "/usr/local/lib/python3.3/dist-packages/pyglet/image/__init__.py", line 2425, in load_animation
    raise first_exception
    File "/usr/local/lib/python3.3/dist-packages/pyglet/image/__init__.py", line 2417, in load_animation
    image = decoder.decode_animation(file, filename)
    File "/usr/local/lib/python3.3/dist-packages/pyglet/image/codecs/gdkpixbuf2.py", line 121, in decode_animation
    gif_stream = gif.read(file)
    File "/usr/local/lib/python3.3/dist-packages/pyglet/image/codecs/gif.py",line 85, in read
    raise ImageDecodeException('Not a GIF stream')
    pyglet.image.codecs.ImageDecodeException: Not a GIF stream

    =======================================================

    From earlier discussions, I know that distutils automatically executes 2to3on the pyglet core module, when you invoke pyglet's setup.py file from Python 3. The setup script does not appear to run 2to3 on the code outside ofthe package itself. And while I doubted that the KeyError I saw above wasa Python 2/3 compatibility issue, I tried running 2to3 on animation.py anyway. 2to3 seems to agree with me, reporting back "RefactoringTool: No files need to be modified."

    Finally, I got errors when trying to run pyglet-1.2alpha1/tests/test.py. At first, it looked like the fix would be easy:

    =======================================================

    File "tests/test.py", line 274
    print '-' * 78
    ^
    SyntaxError: invalid syntax

    =======================================================

    Clearly this was a problem for 2to3, so I ran it on test.py. It corrected that one print statement, and nothing else. Then I ran test.py again. This time I got a deeper problem:

    =======================================================

    Traceback (most recent call last):
    File "test.py", line 215, in <module>
    import tests.regression
    File "../tests/regression/__init__.py", line 11, in <module>
    from pyglet.image import get_buffer_manager
    File "../pyglet/__init__.py", line 276
    print '[%d] %s%s %s' % (thread, indent, name, location)
    ^
    SyntaxError: invalid syntax

    =======================================================

    This error suggests that, during the build and install process, 2to3 left some code uncorrected in pyglet/__init__.py. This has me worried. Could there be other code that 2to3 failed to correct? I don't want to offer my students a tool, only to have it crash on them.

    So, there you have it, the two errors that I am encountering. If anyone has any advice, I would appreciate it. Thanks!
     
    John Ladasky, Jul 29, 2013
    #1
    1. Advertising

  2. On 29 July 2013 23:04, John Ladasky <> wrote:

    > For whatever reason, the pyglet package is getting a lot of attention on
    > c.l.python these past few days. I am guilty of generating some of that
    > potentially off-topic conversation myself. At the end of my last thread, I
    > reported that I had found the pyglet-users newsgroup, and would direct my
    > questions there.
    >
    > https://groups.google.com/d/msg/comp.lang.python/ARtI0GC9RHc/_6URRrhz7nUJ



    I suggest you redirect to the archives from
    http://mail.python.org/pipermail/python-list/.


    > Well, I joined pyglet-users. I have waited for about 36 hours for the
    > moderator to approve my first post asking for help. Several other posts
    > have appeared, but not mine. I don't think that I was impolite.
    >
    > Apologies to everyone, but I'm going to ask my questions here. As you may
    > recall, I'm teaching some adolescent computer programming students. I need
    > a Python 3-compatible GUI, preferably one oriented towards games. I might
    > have that GUI in hand, but I need to test it myself first. I've been
    > researching this issue for over a week. I have a student tomorrow, so I'm
    > facing a bit of a deadline. (Yeah, I could teach him about B-trees
    > instead, but... you know, kids.)
    >
    > In my own defense, I'm not entirely certain that the problems I have
    > encountered are specific to pyglet. They might have to do with the
    > limitations of the 2to3 program.
    >
    > I'm starting with my own Ubuntu 13.04 system. I downloaded
    > pyglet-1.2alpha1, unzipped it and executed "sudo python3 setup.py install",
    > as I have done with many a package. Then I tried running various programs
    > in two directories (these programs are also on the pyglet.org web site).
    >
    > pyglet-1.2alpha1/examples/programming_guide/hello_world.py runs fine.
    >
    > pyglet-1.2alpha1/examples/programming_guide/image_viewer.py also runs fine.
    >
    > pyglet-1.2alpha1/examples/programming_guide/animation.py produces an
    > error. Here's the traceback.
    >

    ....

    > From earlier discussions, I know that distutils automatically executes
    > 2to3 on the pyglet core module, when you invoke pyglet's setup.py file from
    > Python 3. The setup script does not appear to run 2to3 on the code outside
    > of the package itself. And while I doubted that the KeyError I saw above
    > was a Python 2/3 compatibility issue, I tried running 2to3 on animation.py
    > anyway. 2to3 seems to agree with me, reporting back "RefactoringTool: No
    > files need to be modified."
    >
    > Finally, I got errors when trying to run pyglet-1.2alpha1/tests/test.py.
    > At first, it looked like the fix would be easy:
    >

    ....

    > Clearly this was a problem for 2to3, so I ran it on test.py. It corrected
    > that one print statement, and nothing else. Then I ran test.py again.
    > This time I got a deeper problem:
    >

    ....

    > This error suggests that, during the build and install process, 2to3 left
    > some code uncorrected in pyglet/__init__.py. This has me worried. Could
    > there be other code that 2to3 failed to correct? I don't want to offer my
    > students a tool, only to have it crash on them.
    >
    > So, there you have it, the two errors that I am encountering. If anyone
    > has any advice, I would appreciate it. Thanks!
    >


    Seems relevant:
    https://code.google.com/p/pyglet/is...ec=ID Stars StatusType OpSys Modified Summary


    If
    https://code.google.com/p/pyglet/is...ec=ID Stars StatusType OpSys Modified Summary
    is
    your problem then, for me:

    >>> import pyglet
    >>> pyglet.window

    <pyglet._ModuleProxy object at 0x7ffab02cf690>
    >>> pyglet.window.Window()

    <pyglet.window.xlib.XlibWindow object at 0x7ffab02c7b50>

    Window pops up.
    It works! Sorry.

    What happens when you help(pyglet) and help(pyglet.window) and
    help(pyglet.window.Window)?
     
    Joshua Landau, Jul 30, 2013
    #2
    1. Advertising

  3. John Ladasky

    Ian Kelly Guest

    On Mon, Jul 29, 2013 at 4:04 PM, John Ladasky
    <> wrote:
    > pyglet-1.2alpha1/examples/programming_guide/hello_world.py runs fine.
    >
    > pyglet-1.2alpha1/examples/programming_guide/image_viewer.py also runs fine.
    >
    > pyglet-1.2alpha1/examples/programming_guide/animation.py produces an error. Here's the traceback.
    >
    > =======================================================
    >
    > Traceback (most recent call last):
    > File "/usr/local/lib/python3.3/dist-packages/pyglet/resource.py", line 538, in animation
    > identity = self._cached_animations[name]
    > File "/usr/lib/python3.3/weakref.py", line 69, in __getitem__
    > o = self.data[key]()
    > KeyError: 'dinosaur.gif'
    >
    > During handling of the above exception, another exception occurred:
    >
    > Traceback (most recent call last):
    > File "animation.py", line 62, in <module>
    > animation = pyglet.resource.animation('dinosaur.gif')
    > File "/usr/local/lib/python3.3/dist-packages/pyglet/resource.py", line 540, in animation
    > animation = pyglet.image.load_animation(name, self.file(name))
    > File "/usr/local/lib/python3.3/dist-packages/pyglet/image/__init__.py",line 2425, in load_animation
    > raise first_exception
    > File "/usr/local/lib/python3.3/dist-packages/pyglet/image/__init__.py",line 2417, in load_animation
    > image = decoder.decode_animation(file, filename)
    > File "/usr/local/lib/python3.3/dist-packages/pyglet/image/codecs/gdkpixbuf2.py", line 121, in decode_animation
    > gif_stream = gif.read(file)
    > File "/usr/local/lib/python3.3/dist-packages/pyglet/image/codecs/gif.py", line 85, in read
    > raise ImageDecodeException('Not a GIF stream')
    > pyglet.image.codecs.ImageDecodeException: Not a GIF stream
    >
    > =======================================================
    >
    > From earlier discussions, I know that distutils automatically executes 2to3 on the pyglet core module, when you invoke pyglet's setup.py file from Python 3. The setup script does not appear to run 2to3 on the code outside of the package itself. And while I doubted that the KeyError I saw above was a Python 2/3 compatibility issue, I tried running 2to3 on animation.py anyway. 2to3 seems to agree with me, reporting back "RefactoringTool: No files need to be modified."


    >From the error message my first guess would be that the example is

    broken because the 'dinosaur.gif' file is either missing or corrupt.
    Have you tried running the same example in Python 2?

    > Finally, I got errors when trying to run pyglet-1.2alpha1/tests/test.py. At first, it looked like the fix would be easy:
    >
    > =======================================================
    >
    > File "tests/test.py", line 274
    > print '-' * 78
    > ^
    > SyntaxError: invalid syntax
    >
    > =======================================================
    >
    > Clearly this was a problem for 2to3, so I ran it on test.py. It corrected that one print statement, and nothing else. Then I ran test.py again. This time I got a deeper problem:


    This is in the directory that you extracted the files into, not the
    installation directory, correct? If so, I'm not surprised that the
    files in that location haven't been ported by the installer. The
    question then would be "what's the proper way to run the tests under
    Python 3", which I don't know the answer to.

    > =======================================================
    >
    > Traceback (most recent call last):
    > File "test.py", line 215, in <module>
    > import tests.regression
    > File "../tests/regression/__init__.py", line 11, in <module>
    > from pyglet.image import get_buffer_manager
    > File "../pyglet/__init__.py", line 276
    > print '[%d] %s%s %s' % (thread, indent, name, location)
    > ^
    > SyntaxError: invalid syntax
    >
    > =======================================================
    >
    > This error suggests that, during the build and install process, 2to3 leftsome code uncorrected in pyglet/__init__.py. This has me worried. Could there be other code that 2to3 failed to correct? I don't want to offer my students a tool, only to have it crash on them.


    The traceback is using ../pyglet, not your system installation of
    pyglet, so as with the above it looks like this hasn't been ported
    because it's the raw copy in the installation directory. If that code
    had not been ported in the system installation then you would not even
    be able to "import pyglet" without getting an error, which you clearly
    are able to do since you said the first two examples worked for you.
     
    Ian Kelly, Jul 30, 2013
    #3
  4. John Ladasky

    John Ladasky Guest

    Thanks for your reply, Joshua.

    From the interpreter, I too can import pyglet, instantiate a pyglet.window.Window, and have it pop up (although, following your directions, now I can't CLOSE it because you didn't assign a name to it! :^]). I can get all the help information as well.

    It looks like Ian is on the right track (see below). If I remove tests folder from within the pyglet-1.2alpha1 folder and then try to run test.py, it starts.
     
    John Ladasky, Jul 30, 2013
    #4
  5. John Ladasky

    John Ladasky Guest

    Grrrr. Ian, thank you, you gave me a clue. I thought I was being careful about avoiding local imports. I just removed the tests directory from inside the pyglet-1.2alpha1 directory and tried running it from its new location. That got rid of the error message which was displaying uncorrected Python 2.x code, and now I am running tests.

    I'm getting one problem. After a few tests run, I can't close a window. Iam normally closing each interactive test with the ESC key. But when thatfails I try clicking with the mouse. This also fails. This broken behavior appears to be triggered when the window created by pyglet overlaps my terminal window and thereby steals the focus. Any idea why that might be happening?

    The GIF problem in animation.py persists in Python 3.3. I tried it in Python 2 as you suggested, and it works there. Odd.
     
    John Ladasky, Jul 30, 2013
    #5
  6. On Tue, Jul 30, 2013 at 1:47 AM, John Ladasky
    <> wrote:
    > I'm getting one problem. After a few tests run, I can't close a window. I am normally closing each interactive test with the ESC key. But when that fails I try clicking with the mouse. This also fails. This broken behavior appears to be triggered when the window created by pyglet overlaps my terminal window and thereby steals the focus. Any idea why that might be happening?



    When you say "steals the focus", what exactly do you mean? Do the
    windows normally get created without focus, but occasionally focus is
    set to that window? Seems odd. If that's the case, is there any
    difference if you click outside the window (eg on your terminal) and
    then back in? Maybe there's something happening on gotfocus that
    should happen on create.

    ChrisA
     
    Chris Angelico, Jul 30, 2013
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Holkner

    ANN: pyglet 1.0beta1

    Alex Holkner, Nov 9, 2007, in forum: Python
    Replies:
    0
    Views:
    301
    Alex Holkner
    Nov 9, 2007
  2. Alex Holkner

    ANN: pyglet 1.0

    Alex Holkner, Jan 17, 2008, in forum: Python
    Replies:
    0
    Views:
    297
    Alex Holkner
    Jan 17, 2008
  3. Alex Holkner

    ANN: pyglet 1.1

    Alex Holkner, Aug 12, 2008, in forum: Python
    Replies:
    0
    Views:
    310
    Alex Holkner
    Aug 12, 2008
  4. Andrew Berg
    Replies:
    0
    Views:
    345
    Andrew Berg
    Jun 16, 2012
  5. John Ladasky
    Replies:
    9
    Views:
    171
    John Ladasky
    Jul 27, 2013
Loading...

Share This Page