I've looked at other posts on this topic, but I was wondering if there was some way of doing this without changing directly into the directory of the library or explicitly specifying the absolute path such as through sys.path.append or using the PATH or CLASSPATH environment variables on Windows. What I'm trying to do right now is load "jvm.dll"
If the DLL in question didn't have any dependencies, it would be possible to load the library by passing the ctypes factory the absolute path to the DLL (which you could determine however you wish). However, DLLs are often bundled together and have inter-dependencies. Your most robust bet is probably to add the DLL's containing directory to
os.environ['PATH'] to ensure that the dependent DLLs can be automatically resolved by the OS library loader. Note, you can do this just temporarily if you're worried about polluting your environment.
dll_dir = r'c:\foo\bar\path' tmp = os.environ['PATH'] os.environ['PATH'] = dll_dir + ';' + tmp ctypes.LoadLibrary( dll_name ) os.environ['PATH'] = tmp