Issue when snap uses python's ctype.util.find_library

I’ve hit an issue when packaging a python app, the snap package tries to load a library that exists on the host rather than the one in snap. The app uses ctypes.util.find_library to look for the library and seems it is causing the problem.

I’ve made a simple test with this test.py and snapcraft.yaml. This test snap is very simple and does not contain any extra libraries, but if your host has libsodium, the snap will report the library can be found.

If I build the test snap with devmode confinement, then execute snap run --shell test and run ldconfig in it, and then run the test snap again, it will report libsodium cannot be found, which makes me wonder if the problem is related to ldconfig cache.

Thanks.

devmode and strict mode snaps both run in their own mount namespace using the core snap as a runtime, or whatever runtime you specify with base. You’ll need to ship libsodium in your snap and then convince find_library that you have it (eg, perhaps by setting LD_LIBRARY_PATH).

This might be something with your snapcraft.yaml; perhaps @sergiusens can comment.

We have a patch, our last remaining patch for python and classic confinement over at https://github.com/snapcore/snapcraft/blob/master/patches/ctypes_init.diff

The goal is to find time and create a generic solution that can be part of future versions of python and maybe backported and SRUed into Ubuntu so everyone reaps the benefits.

Sorry for resurrecting this old thread, but is this still the plan? If so, is there a good place for me to track this work? I hit this problem recently myself.

Yes, but I would encourage anyone with deb packaging experience or a python core developer to take a stance at this if it is really urgent.

I wouldn’t say it’s really urgent, but like snapcraft, we’re now maintaining a patch/fork to make this work in our classic snap which I would rather not do.

I unfortunately don’t have significant experience with either deb packaging or Python core development, but I may try and help work on this regardless. Any suggestions or pointers to help myself or others work towards a long term solution here are appreciated.