I have a python app that, using ctypes
, loads and calls a dynamic C library.
I want to create a zipapp
with this application, but I don't know how to obtain the path to the library from within the app. The directory tree is:
mypackage/
├── __init__.py
├── __main__.py
└── lib
└── libmylyb.so
and __main__.py
is:
#!/usr/bin/env python3
from ctypes import *
h = cdll.LoadLibrary("./lib/libmylib.so")
...
I create the zipapp by doing:
python3 -m zipapp mypackage
but when I try to execute it, I get an error because the above library is not found.
I'm aware that pkgutil.get_data
can be used to read the file content, and I guess that I could read the library binary data, write it in a temp file and the load it, but is there any better way to do what I want?