python: rework dll load logging on windows (Fix #4579)

DevNote:
to enable trace you can use

```py
import logging
logging.basicConfig(level=logging.DEBUG)

from ortools...
```
This commit is contained in:
Corentin Le Molgat
2025-03-17 10:40:55 +01:00
parent 21d88dc1f9
commit 60e490aee3

View File

@@ -45,15 +45,17 @@ __docformat__ = "markdown" # explicitly disable rST processing above.
__version__ = "@PROJECT_VERSION@"
import os
import logging
def _load_ortools_libs():
"""Load shared libraries on Windows"""
if os.name == "nt":
logger = logging.getLogger("ortools")
try:
from ctypes import WinDLL
basedir = os.path.dirname(__file__)
except:
pass
logger.error(f"ImportError: Cannot import WinDLL")
else:
for dll in ["zlib1.dll",
"abseil_dll.dll", "utf8_validity.dll", "re2.dll", "libprotobuf.dll",
@@ -61,8 +63,10 @@ def _load_ortools_libs():
"ortools.dll"]:
dll_path = os.path.join(basedir, ".libs", dll)
if os.path.exists(dll_path):
print(f"load {dll_path}...")
logger.debug(f"Loading {dll_path}...")
WinDLL(dll_path)
else:
logger.debug(f"Cannot find {dll_path}")
_load_ortools_libs()