I have a Python module, wrapper.py
, that wraps a C DLL. The DLL lies in the same folder as the module. Therefore, I use the following code to load it:
I always add the directory where my DLL is to the path. That works:
os.environ['PATH'] = os.path.dirname(__file__) + ';' + os.environ['PATH']
windll.LoadLibrary('mydll.dll')
Note that if you use py2exe, this doesn't work (because __file__
isn't set). In that case, you need to rely on the sys.executable
attribute (full instructions at http://www.py2exe.org/index.cgi/WhereAmI)