Pyglet resources not loading

pyglet.resource.ResourceNotFoundException: Resource "data/queen.png" was not found on the path.  Ensure that the filename has the correct captialisation

Cosmo and Rectifier pointed out a bug:

pyglet.resource has a cache. This cache gets invalidated by the previous games you played (but didn't happen on my machine, as I played my game first).

Cosmo fixed it by adding (at the top of run_game.py) :

    pyglet.resource.path = ['data']
    pyglet.resource.reindex()

    and removing "data/" from all the resouce loads.

It might be possible to just do:

    pyglet.resource.path = ['.']
    pyglet.resource.reindex()


 

(log in to comment)

Comments

I'm running into this issue with a number of pyglet games. I'm curious why reindexing is required on some systems and not others, apparently. Does anyone know? Is it an operating system difference?
pyglet's resource module cache is entirely in-memory. A reindex is only needed if the path is modified (through pyglet.resource.path.append() or outright replacing the path like the examples above.)

Are you certain that the problem isn't one of capitalisation as mentioned in the error?
Yep, check it out:


christopher@palimpsest:~/Downloads/PyWeek-13-finals/mustache/mustache_day$ ls -hog data/blob.png
-rw-r--r-- 1 537K 2011-09-17 17:43 data/blob.png
christopher@palimpsest:~/Downloads/PyWeek-13-finals/mustache/mustache_day$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyglet
>>> pyglet.resource.texture('data/blob.png')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/pyglet/resource.py", line 599, in texture
    file = self.file(name)
  File "/usr/lib/pymodules/python2.6/pyglet/resource.py", line 383, in file
    raise ResourceNotFoundException(name)
pyglet.resource.ResourceNotFoundException: Resource "data/blob.png" was not found on the path.  Ensure that the filename has the correct captialisation.
>>> pyglet.resource.path = ['.']
>>> pyglet.resource.reindex()
>>> pyglet.resource.texture('data/blob.png')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/pyglet/resource.py", line 599, in texture
    file = self.file(name)
  File "/usr/lib/pymodules/python2.6/pyglet/resource.py", line 383, in file
    raise ResourceNotFoundException(name)
pyglet.resource.ResourceNotFoundException: Resource "data/blob.png" was not found on the path.  Ensure that the filename has the correct captialisation.
>>> pyglet.resource.path = ['data']
>>> pyglet.resource.reindex()
>>> pyglet.resource.texture('blob.png')
<Texture 512x512>
Someone encountered this problem with my entry. I discovered that upgrading to pyglet 1.1.4 seems to fix it. I suspect it's a bug in 1.1.2. If you trace it far enough back into the pyglet internals, 1.1.2 is constructing paths with leading slashes where they shouldn't be if your resource path is just ['.'] like mine is.

See http://pyweek.org/d/4368/ for suggestions!