Issue #57 resolved

ImportError: found ['libSDL2-2.0.so.0'], but it's not usable for the library SDL2

Anonymous created an issue

I get the above error trying to import the SDL2 library.

I'm running 32bit Linux Mint (quantal version), and today compiled and installed the latest SDL2 (2.0.3) from their website (SDL2 is not available in my distros repos), and installed the latest py-sdl2 (0.9.2, tried both versions of installation make and via the setup.py - you never know...) and all those other packages following the instructions on the site.

So I think this cannot be due to a 32/64bit incompatibility, which is described as a frequent cause for this error message in the FAQ.

How can I go on finding the problem?

Comments (10)

  1. Marcus von Appen repo owner

    My best guess is that you suffer from the problem described in issue #48.

    • Assumption I: Your SDL2 library was installed into /usr/local/lib or /opt/lib or some similar path, but not Mint's default path /usr/lib
    • Assumption II: Your linker paths do not include /usr/local/lib (or /opt/lib or whatever)

    Solutions to try, if the both assumptions are correct:

    1. Make sure that the path actually is the problem by adding /usr/local/lib temporarily to the linker paths using export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH on a shell command line and try to import sdl2 again on the same shell
    2. If 1. solved your problem, either add /usr/local/lib to your ld paths (add it to /etc/ld.so.conf) or run ldconfig -n /usr/local/lib on it.

    Let me know, if this fixes your problem.

  2. Moini

    Thank you very much for your quick answer. The temporary solution worked for me and helped finding the cause, while the permanent one does not (tried both ways (2b as normal user and as su)), for whatever reason. It was also gone after I closed the shell...?!...

    I resolved the problem by uninstalling and recompiling SDL2 after configuring with -prefix=/usr, which works. Did the same for SDL2_gfx, which couldn't be found or was deemed to be unusable (strange error message, that...), either.

    Now I tried all the examples from the examples folder and found that they seem to crash / not render correctly if the example window contains letters/fonts.

    It either says 'Speicherzugriffsfehler' (segmentation fault, helloworld.py), or where there should be words in the example (gui.py) - at least I think there should be, on the left -- screenshot4.png --, there are only funny colored dots and no error message on the shell.

    Did an extensive Web search and found that SDL2_ttf was also necessary or at least useful, and thought that maybe its missing caused the segfault/render issue.

    Configured this again with prefix=/usr, and compiled and installed. Unfortunately, this was not the solution... still getting segfault and funny colored pixels, screenshot attached.

    Could you also help me with this? Hope that this is one problem and not two different ones...

  3. Moini

    Put it into Eric, and found the helloworld.py crashes after spriterenderer.render(sprite). So at least this is not caused by any fonts.

  4. Moini

    And in the picture for gui.py, it fails to render the bitmap images correctly, the functionality is good (if I click on the left bottom text input field, I get the text I input in the console, the button clicks are recognized, the checkbox changes color on click). The pictures are available and the files are not broken.

  5. Marcus von Appen repo owner

    I can't recreate that behaviour on any of my test systems. Can you install the SDL2 libraries (along with SDL2_image, _ttf, ...) as debug builds and run everything through gdb:

    ~ gdb python
    (gdb) r examples/helloworld.py
    

    When it breaks, type bt to acquire a backtrace with (hopefully) more information about the source of the segfault.

  6. Moini

    Yippieh!

    After reading 'along with SDL2_image...', it dawned on me that there might be another library missing, because I was sure I had not installed that. Installed it now and - voilà - it works. No segfaults and 'beautiful' buttons.

    So now I have _image, _gfx, _ttf and the basic stuff which comes with SDL2 source. Do I still need further libraries of which I don't know yet that they exist? (Maybe one out of _mixer, _Cbs, _rtf, _net?) EDIT: need _mixer. I'm really a noob in this.

    For those who run into the same problems as I did:

    Could you make pySDL2 check if all the libraries are installed before you allow it to start or make it give a warning that this or that will not work until this or that is installed? And / or could you add the full list of requirements to the documentation (if they are not there and I just missed them...EDIT: I did misunderstand the list, thought all was really optional for me, but I needed it. See post below.)?

    Would you also add a hint for Ubuntu/Mint users on configuring with --prefix=/usr or adding that directory to that ld-config file to avoid the issue of not finding 'usable' libraries?

    And could you modify the 'is not usable'-warning to also include something like 'or you need to check if the libraries are in a folder where your system can find it (see /etc/ld.so.conf).'? (although the adding to the file didn't work for me, the path was already in the .conf files it included, but was nicely ignored:

    contents of my etc/ld.so.conf:

    include /etc/ld.so.conf.d/*.conf
    /usr/local/lib //added that line, but maybe I did it wrong, didn't help
    

    contents of my preexisting etc/ld.so.conf.d/libc.conf:

    # libc default configuration
    /usr/local/lib
    

    (or do the names of the files matter? A friend told me they don't)

    Anyway, this Linux Mint bug(?) isn't your problem..., Thank you very much for your help! Now I can finally start my little game :-D !

  7. Moini

    oh - okay, I found the list. Still need mixer for sound. But if they are all optional, one can only ever draw the images by software... Could you modify the list at http://pysdl2.readthedocs.org/en/latest/install.html#getting-the-sources to:

    <p>PySDL2 also offers support for the following SDL-related libraries. You will also need:</p>
    <ul class="simple">
    <li>SDL2_image, if you want to render bitmap images  (<a class="reference external" href="http://www.libsdl.org/projects/SDL_image/">http://www.libsdl.org/projects/SDL_image/</a>)</li>
    <li>SDL2_mixer, if you need sound  (<a class="reference external" href="http://www.libsdl.org/projects/SDL_mixer/">http://www.libsdl.org/projects/SDL_mixer/</a>)</li>
    <li>SDL2_ttf, if you want to write text using ttf-fonts  (<a class="reference external" href="http://www.libsdl.org/projects/SDL_ttf/">http://www.libsdl.org/projects/SDL_ttf/</a>)</li>
    <li>SDL2_gfx (**didn't understand what this is for, graphic primitives are there also without it, please fill in!**)              (<a class="reference external" href="http://www.ferzkopp.net/Software/SDL_gfx-2.0/">http://www.ferzkopp.net/Software/SDL_gfx-2.0/</a>)</li>
    
  8. Marcus von Appen repo owner

    Great to hear that you tracked that issue down. I'm somewhat surprised that the examples misbehave in such an unpredictable manner, if SDL2_image is not around. I'll recheck the code to issue warnings or errors instead of crashing.

    SDL2_image is only necessary, if you want to use non-BMP image formats. Alternatively, PIL (the Python Imaging Library) can fill that gap, if installed.

    SDL2_gfx offers more advanced graphics primitives that SDL2's Renderer does.

    Any of those however should be completely optional and the SDL2 internals should fail with a clear error message, if the libraries are not installed. As written above, this does not seem to happen properly at the moment (for SDL2_image) and I'll investigate this.

    Thanks!

  9. Marcus von Appen repo owner
    • sdl2.ext.load_image() tries to use sdl2.SDL_LoadBMP() now, if SDL2_image and PIL are not found
    • sdl2.ext.get_image_formats() only returns BMP image support now, if SDL2_image and PIL are not found
    • fixed issue #57: if SDL2_image is not installed and PIL is used, the loaded pixel buffer of the image file is not referenced anymore after returning from sdl2.ext.load_image(), causing random segmentation faults

    → <<cset d11faa790c59>>

  10. Log in to comment