Can’t import dll module in Python

Starting with Python 3.8, the .dll search mechanism has changed (Win specific).

According to [Python.Docs]: os.add_dll_directory(path) (emphasis is mine):

Add a path to the DLL search path.

This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes.

Availability: Windows.

So, you could do:

os.add_dll_directory("${path_to_working_dlls_directoy}")

where ${path_to_working_dlls_directoy} is a placeholder for the actual path and it (obviously) should be replaced by it.

You can check [SO]: PyWin32 and Python 3.8.0 (@CristiFati’s answer) (which although it seems very different, has the same cause), for more details.

P.S.: Nix OSes are not impacted.

Leave a Comment