SDL2 and PYSDL2_DLL_PATH

Hi, i’m trying to snap TauonMusicBox and i stumble on an error with lib SDL2 import. On my first try, i got the following error :

RuntimeError: could not find any library for SDL2 (PYSDL2_DLL_PATH: unset)

FTR, i’ve read about this on this post How best to link to SDL2

After reading this post Using git from a program i’ve tried different settings to get the path working with environment key word with no luck, still got an error :

ImportError: could not find any library for SDL2 (PYSDL2_DLL_PATH: :/snap/tauon/x2/usr/lib/x86_64-linux-gnu)

For now, i’m setting PYSDL2_DLL_PATH: $PYSDL2_DLL_PATH:$SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET in environment since that’s where i can see the lib reside in prime directory.

My snap is here https://github.com/brunob/TauonMusicBox/blob/snapcraft/snapcraft.yaml and the related issue on original repo is https://github.com/Taiko2k/TauonMusicBox/issues/207

Does anyone have been experienced with this lib and could give me hints about this ?

the debian package of pysdl2 seems to install its stuff in $PYTHONPATH/dist-packages/sdl2

https://packages.ubuntu.com/disco/all/python3-sdl2/filelist

i’d search for a file thats typically in there like:

find prime/ -name '*sdlmixer.py*'

to find the actual path for the variable …

Thx for answering :slight_smile:

I’ve tried with PYSDL2_DLL_PATH: $PYSDL2_DLL_PATH:$SNAP/lib/python3.6/site-packages/sdl2 which fails too, and with PYTHONPATH: $PYTHONPATH:$SNAP/lib/python3.6/site-packages with no more luck :\

well, did you actually find the file in that path ?

Yes, i can find libSDL2-2.0.so.0 in prime/usr/lib/x86_64-linux-gnu/.

It seems related to Issue when snap uses python's ctype.util.find_library mentioning a patch here https://github.com/snapcore/snapcraft/blob/master/patches/ctypes_init.diff but i can’t figure if this is available for now :\

i literally meant searching for sdlmixer.py or something equivalent like “dll.py” from the above file list.

libSDL2 is irrelevant for the issue you are hitting (it is indeed needed for the backend support but your app is complaining about pysdl2 not about libsdl2 itself)

Sorry but i’m a bit lost, since the error was RuntimeError: could not find any library for SDL2 i was thinking the problem was the lib path.

I’ve tried to follow you advice and setting this PYTHONPATH: $PYTHONPATH:$SNAP/lib/python3.6/site-packages/sdl2 in environment, which led me to a new error :\

Traceback (most recent call last):
  File "/snap/tauon/x8/tauon.py", line 341, in <module>
    import platform
  File "/snap/tauon/x8/lib/python3.6/site-packages/sdl2/platform.py", line 2, in <module>
    from .dll import _bind
ImportError: attempted relative import with no known parent package

Trying to narrow the problem, as said here https://github.com/Taiko2k/TauonMusicBox/issues/207#issuecomment-555779442

Would likely be that the underlying ctypes.util.find_library function is not finding (or accepting) the SDL2 library files.

find_library fails in sdl2/dll.py here https://github.com/marcusva/py-sdl2/blob/master/sdl2/dll.py#L34

I can go further if i set PYSDL2_DLL_PATH: $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET in snap yaml + patching pattern here https://github.com/marcusva/py-sdl2/blob/master/sdl2/dll.py#L19 as pattern = "lib%s.so.0" since the lib files are suffixed by 0 in prime folder => it works

… to be continued

To conclude, there is a bug with ctypes.util.find_library and another bug with pysdl2 that prevent it to correctly load .so* files, i’ve opened an issue for this one https://github.com/marcusva/py-sdl2/issues/148