2

For loading DLL libraries in Python 3.8+ I understand the the path environemnt variable is not used anymore to search for dependencies. Therefore the function os. add_dll_directory() should be used to add directories to the search path. That works on my machine.

Is it possible that the directories are added permanently? I have noticed that now everything is loaded correctly also without adding the dll directory first using the function mentioned. I cannot reproduce the error where the dependencies were not found.

From the documentation I did not understand that anything is changed permanently.

Chris
  • 899
  • 2
  • 17
  • 25

1 Answers1

1

[Python.Docs]: os.add_dll_directory(path) calls [MS.Docs]: AddDllDirectory function (libloaderapi.h) which states (emphasis is mine):

Adds a directory to the process DLL search path.

So, it has effect during the lifetime of the calling process, or (according to Python doc) until the returned object is closed (in that case RemoveDllDirectory is called under the hood) either manually or at with statement exit.

Related (more or less):

CristiFati
  • 38,250
  • 9
  • 50
  • 87
  • 1
    Just for everybodys information: It seems that Python 3.8 and 3.9 behave differently in this regard. While I need to call the add_dll_directory function in 3.8, it works without it in 3.9. – Chris Jun 07 '21 at 12:35