Issue #21 resolved

factory.from_image fails if neither SDL_image nor PIL are installed

Scott Harper
created an issue

Neither library is listed as required (and PIL isn't mentioned at all, and isn't compatible with Python 3.x). Should there be some mention of this on the website? Should the library report an error when neither library manages to import?

----------------- original bug ----------------- Running on Windows, I am following the tutorial, and everything works great up until the following line:

sprite = factory.from_image(RESOURCES.get_path("imagename.bmp"))

Here is the traceback:

Traceback (most recent call last):
  File "main.py", line 25, in <module>
    sprite = factory.from_image(RESOURCES.get_path("Timmy.png"))
  File "C:\Python33\lib\site-packages\sdl2\ext\sprite.py", line 405, in from_image
    return self.from_surface(load_image(fname), True)
  File "C:\Python33\lib\site-packages\sdl2\ext\sprite.py", line 423, in from_surface
    s = SoftwareSprite(tsurface, free)
  File "C:\Python33\lib\site-packages\sdl2\ext\sprite.py", line 299, in __init__
    raise TypeError("surface must be a SDL_Surface")
TypeError: surface must be a SDL_Surface

I have checked that sdl2ext.load_image(...) does not fail for the same file path.

Comments (5)

  1. Brett Calcott

    I'm on Mac OSX 10.8.5 and get exactly the same error with any resource loading.

    From the examples folder:

    > python helloworld.py
    2013-10-19 19:09:09.345 Python[14189:1307] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/1g/1hntfw254d1gjqv9fp0_dv4h0000gp/T/org.python.python.savedState
    Using software rendering
    Traceback (most recent call last):
      File "helloworld.py", line 87, in <module>
        sys.exit(run())
      File "helloworld.py", line 59, in run
        sprite = factory.from_image(RESOURCES.get_path("hello.bmp"))
      File "/Library/Python/2.7/site-packages/sdl2/ext/sprite.py", line 405, in from_image
        return self.from_surface(load_image(fname), True)
      File "/Library/Python/2.7/site-packages/sdl2/ext/sprite.py", line 423, in from_surface
        s = SoftwareSprite(tsurface, free)
      File "/Library/Python/2.7/site-packages/sdl2/ext/sprite.py", line 299, in __init__
        raise TypeError("surface must be a SDL_Surface")
    TypeError: surface must be a SDL_Surface
    

    I've installed SDL2 using "brew" and I'm using the master branch from bitbucket SHA 2d125a97e1c63b8b5230106fcc4c6dcc2a8a04a0

  2. Scott Harper reporter

    I've dug into the code a bit, and it looks like the load_image function in ext/image.py requires EITHER sdlimage (which is described as optional) or PIL (Python Image Library, which isn't listed as a dependency on the site and doesn't appear to be included with a default python distro...)

    I can't use PIL because I'm running with Python 3.3; but after installing SDL_Image, the demo seems to work appropriately.

    Should there be some kind of error message when image.py fails to load EITHER image library?

  3. Log in to comment