8000 Add path used by pip's build isolation procedure to DLL search · pytorch/pytorch@f2b49a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2b49a9

Browse files
committed
Add path used by pip's build isolation procedure to DLL search
Without this, trying to `import torch` in a downstream `setup.py` file would result in ``` The specified module could not be found. Error loading "C:\...\pip-build-env-himl3xh3\normal\Lib\site-packages\torch\lib\shm.dll" or one of its dependencies." ``` This seems to be because pip does not use a full virtualenv for build isolation, instead creating directories and manually adding them to `sys.path`
1 parent 0246b28 commit f2b49a9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

torch/__init__.py

Lines changed: 9 additions & 2 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _load_dll_libraries() -> None:
154154
pfiles_path = os.getenv("ProgramFiles", r"C:\Program Files")
155155
py_dll_path = os.path.join(sys.exec_prefix, "Library", "bin")
156156
th_dll_path = os.path.join(os.path.dirname(__file__), "lib")
157-
usebase_path = os.path.join(
157+
userbase_path = os.path.join(
158158
sysconfig.get_config_var("userbase"), "Library", "bin"
159159
)
160160

@@ -167,9 +167,16 @@ def _load_dll_libraries() -> None:
167167
else:
168168
base_py_dll_path = ""
169169

170+
# when using pip install on a project that depends on PyTorch, pip installs
171+
# torch & mkl in a custom path that's included in sys.path but does not match
172+
# any of the other DLLs path above, so we need to manually add it here.
173+
mkl_dll_path = os.path.join(
174+
os.path.dirname(__file__), "..", "..", "..", "Library", "bin"
175+
)
176+
170177
dll_paths = [
171178
p
172-
for p in (th_dll_path, py_dll_path, base_py_dll_path, usebase_path)
179+
for p in (th_dll_path, py_dll_path, base_py_dll_path, userbase_path, mkl_dll_path)
173180
if os.path.exists(p)
174181
]
175182

0 commit comments

Comments
 (0)
0