add python root bin to windows load path. (#146573)

This PR is extend python root bin path to dll load list.
It makes PyTorch robust and compatible to more dependency libraries, such as `intel-pti`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/146573
Approved by: https://github.com/EikanWang, https://github.com/albanD
This commit is contained in:
Han, Xu 2025-03-21 00:48:43 +00:00 committed by PyTorch MergeBot
parent 90543e90a0
commit 2975664fb0

View File

@ -167,6 +167,7 @@ if sys.platform == "win32":
usebase_path = os.path.join(
sysconfig.get_config_var("userbase"), "Library", "bin"
)
py_root_bin_path = os.path.join(sys.exec_prefix, "bin")
# When users create a virtualenv that inherits the base environment,
# we will need to add the corresponding library directory into
@ -179,7 +180,13 @@ if sys.platform == "win32":
dll_paths = [
p
for p in (th_dll_path, py_dll_path, base_py_dll_path, usebase_path)
for p in (
th_dll_path,
py_dll_path,
base_py_dll_path,
usebase_path,
py_root_bin_path,
)
if os.path.exists(p)
]