Unable to find DLL when loading PyGObject in Windows
In Python 3.8, a new os.add_dll_directory
method was added to make loading DLLs in Windows more consistent.
!193 (closed) attempted to fix this by upstreaming gvsbuild patches, but was closed by !206 (merged). It looks like !206 (merged) added a function to set the DLL search path during initialization of the test environment. I don't think that fixed the issue.
The impact of this is that even if I compile GTK successfully with MSVC, and add it to the Path, INCLUDE, and LIB, I am still not able to pip install PyGObject
in Windows.
Would explicitly calling the add_dll_directory
in gi/__init__.py
module prior to attempting to import _gi
be an acceptable solution? If so I can create a MR.
if sys.platform == "win32" and sys.version_info >= (3, 8):
env_path = os.environ.get("PATH", "").split(os.pathsep)
first_gtk_path = next(
filter(
lambda path: path is not None
and Path.is_file(Path(path) / "girepository-1.0-1.dll"),
env_path,
),
None,
)
if first_gtk_path:
with os.add_dll_directory(first_gtk_path):
from . import _gi
else:
from . import _gi