diff --git a/win32/Lib/pywintypes.py b/win32/Lib/pywintypes.py index 94f021eb56..8f03e0d7a2 100644 --- a/win32/Lib/pywintypes.py +++ b/win32/Lib/pywintypes.py @@ -87,23 +87,18 @@ def __import_pywin32_system_module__(modname, globs): # In a worst-case, it means, say 'python -c "import win32api"' # will not work but 'python -c "import pywintypes, win32api"' will, # but it's better than nothing. - # We prefer the "user" site-packages if it exists... - if found is None: - import site - maybe = os.path.join(site.USER_SITE, "pywin32_system32", filename) - if os.path.isfile(maybe): - found = maybe + # We use the same logic as pywin32_bootstrap to find potential location for the dll + # Simply import pywin32_system32 and look in the paths in pywin32_system32.__path__ - # Or the "global" site-packages. if found is None: - import sysconfig + import pywin32_system32 - maybe = os.path.join( - sysconfig.get_paths()["platlib"], "pywin32_system32", filename - ) - if os.path.isfile(maybe): - found = maybe + for path in pywin32_system32.__path__: + maybe = os.path.join(path, filename) + if os.path.isfile(maybe): + found = maybe + break if found is None: # give up in disgust.