Pyglet on Python3.x, problems

John Ladasky john_ladasky at sbcglobal.net
Mon Jul 29 18:04:18 EDT 2013


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 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.

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

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."

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!



More information about the Python-list mailing list