Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions win32/Lib/pywin32_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

try:
import pywin32_system32
except ImportError: # Python ≥3.6: replace ImportError with ModuleNotFoundError
except ImportError:
pass
else:
import os
Expand All @@ -17,5 +17,18 @@
# https://docs.python.org/3/reference/import.html#path-attributes-on-modules
for path in pywin32_system32.__path__:
if os.path.isdir(path):
os.add_dll_directory(path)
try:
# First try the preferred method
os.add_dll_directory(path)
except Exception:
# If anything fails, try to modify PATH if it exists
try:
if "PATH" in os.environ:
os.environ["PATH"] = path + os.pathsep + os.environ["PATH"]
else:
# If PATH doesn't exist, just create it
os.environ["PATH"] = path
except Exception:
# Last resort - if nothing works, just pass silently
pass
break