Reputation: 979
I have python module that wraps functions from a DLL in the same directory, and loads the library using ctypes.
__lib = cdll.LoadLibrary("deviceSys.dll")
Here's my directory Layout:
deviceSys
- wrapper.py
- deviceSys.dll
- __init__.py
I'm following the package guidelines, but I'm not sure how to load the dll once my code is a module on PyPi. For instance, if I use ctypes to load the library, it produces an error, because it's searching locally:
OSError: [WinError 126] The specified module could not be found
I need to somehow embed my dll or search for the file within included resources for the package. Is there a way to do this?
Upvotes: 2
Views: 4969
Reputation: 979
I figured it out. You need to add the DLL to the package_data
in the setup.py
:
include_package_data=True,
package_data={"devsys": ['deviceSystem.dll']},
To get the file from within wrapper.py
use the following:
dir = os.path.dirname(sys.modules["devsys"].__file__)
path = os.path.join(dir, "deviceSystem.dll")
__lib = cdll.LoadLibrary(path)
Upvotes: 5