I have a python package, mymodule, that contains a shared library file and an init.py file. The init.py file declares various functions and also loads the shared library file:
lib = ctypes.cdll.LoadLibrary('mydll')
I want the user to be able place mymodule anywhere in the filesystem, and import it into his or her module, usermodule.
This works fine if mymodule is in the directory usermodule. However, when mymodule is located somewhere else, I have not been able to find a solution to have init.py to load mydll, even though they are both within mymodule. Actually I can get it to work by explicitly stating the absolute path, but I cannot use this solution in practice, since I don't know where the user will place mymodule in the filesystem.
Within the init file of mymodule, I have tried to set the path to mymodule using pathlib:
from pathlib import Path
path = Path('mymodule').absolute()
However,print(path) returns the path of usermodule, which is importing mymodule. Since the path is not correct, there is an error 'module not found' when init.py tries to load mydll.
Is there a way to use pathlib to have mymodule load mydll in my situation?
Thanks for any help you can provide!