From 7d2de404372b0a77c5dec825c62f739e75a351ee Mon Sep 17 00:00:00 2001 From: Andrey Talman Date: Thu, 6 Oct 2022 11:49:29 -0400 Subject: [PATCH] Fix windows python 3.8 required dlls not found (#6715) * Fix windows python 3.8 * Update torchvision/extension.py Co-authored-by: Vasilis Vryniotis * Update torchvision/extension.py Co-authored-by: Vasilis Vryniotis --- torchvision/extension.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/torchvision/extension.py b/torchvision/extension.py index 3bad8351b23..702e7e33b33 100644 --- a/torchvision/extension.py +++ b/torchvision/extension.py @@ -16,6 +16,18 @@ def _has_ops(): try: + # On Windows Python-3.8.x has `os.add_dll_directory` call, + # which is called to configure dll search path. + # To find cuda related dlls we need to make sure the + # conda environment/bin path is configured Please take a look: + # https://stackoverflow.com/questions/59330863/cant-import-dll-module-in-python + if os.name == "nt" and sys.version_info >= (3, 8) and sys.version_info < (3, 9): + env_path = os.environ["PATH"] + path_arr = env_path.split(";") + for path in path_arr: + if os.path.exists(path): + os.add_dll_directory(path) # type: ignore[attr-defined] + lib_path = _get_extension_path("_C") torch.ops.load_library(lib_path) _HAS_OPS = True