import os
import sys

paths = os.environ['PATH'].split(";")

if 'OSGEO4W_ROOT' not in os.environ:
    o4w = os.path.normpath(
        os.path.join(
            os.path.dirname(os.path.realpath(__file__)),
            "..", "..", "..", "..")
    )
    os.environ['OSGEO4W_ROOT'] = o4w
    for p in [
        "bin",
        "apps\\qt5\\bin",
        f"apps\\Python312",
        f"apps\\Python312\\Scripts"
    ]:
        p = os.path.join(o4w, p)
        if os.path.exists(p):
            paths.insert(0, p)

for p in paths:
    if os.path.exists(p):
        os.add_dll_directory(p)
