Skip to content

Commit d28f514

Browse files
committed
Fix python package-DLLs not being found
This PR introduced `winmode=0` for loading DLLs during import: #5259 This however leads to directories added via `os.add_dll_directory` not being considered, when loading DLLs (see #7104 (comment)). In particular this leads to open3d/tbb12.dll not being found. Fix this by going back to the default DLL-search mode (`winmode=None`). In order to still be able to find CUDA-DLLs, that are not part of the open3d-package, search their directory in PATH and explicitly add it to the DLL-search-locations for CUDA-builds.
1 parent 8dbccb6 commit d28f514

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Main
2+
- Fix DLLs not being found in Python-package. Also prevent PATH from being searched for DLLs, except CUDA (PR #7108)
23
- Fix MSAA sample count not being copied when FilamentView is copied
34
- Fix TriangleMesh::SamplePointsUniformly and TriangleMesh::SamplePointsPoissonDisk now sampling colors from mesh if available (PR #6842)
45
- Fix TriangleMesh::SamplePointsUniformly not sampling triangle meshes uniformly (PR #6653)

python/open3d/__init__.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# https://github.com/dmlc/xgboost/issues/1715
1616
import os
1717
import sys
18+
import re
1819

1920
os.environ["KMP_DUPLICATE_LIB_OK"] = "True"
2021
# Enable thread composability manager to coordinate Intel OpenMP and TBB threads. Only works with Intel OpenMP.
@@ -27,21 +28,6 @@
2728
from open3d._build_config import _build_config
2829

2930

30-
def load_cdll(path):
31-
"""
32-
Wrapper around ctypes.CDLL to take care of Windows compatibility.
33-
"""
34-
path = Path(path)
35-
if not path.is_file():
36-
raise FileNotFoundError(f"Shared library file not found: {path}.")
37-
38-
if sys.platform == "win32" and sys.version_info >= (3, 8):
39-
# https://stackoverflow.com/a/64472088/1255535
40-
return CDLL(str(path), winmode=0)
41-
else:
42-
return CDLL(str(path))
43-
44-
4531
if sys.platform == "win32": # Unix: Use rpath to find libraries
4632
_win32_dll_dir = os.add_dll_directory(str(Path(__file__).parent))
4733

@@ -50,7 +36,7 @@ def load_cdll(path):
5036
# Load CPU pybind dll gracefully without introducing new python variable.
5137
# Do this before loading the CUDA pybind dll to correctly resolve symbols
5238
try: # StopIteration if cpu version not available
53-
load_cdll(str(next((Path(__file__).parent / "cpu").glob("pybind*"))))
39+
CDLL(str(next((Path(__file__).parent / "cpu").glob("pybind*"))))
5440
except StopIteration:
5541
warnings.warn(
5642
"Open3D was built with CUDA support, but Open3D CPU Python "
@@ -59,9 +45,23 @@ def load_cdll(path):
5945
ImportWarning,
6046
)
6147
try:
48+
if sys.platform == "win32" and sys.version_info >= (3, 8):
49+
# Since Python 3.8, the PATH environment variable is not used to find DLLs anymore.
50+
# To allow Windows users to use Open3D with CUDA without running into dependency-problems,
51+
# look for the CUDA bin directory in PATH and explicitly add it to the DLL search path.
52+
cuda_bin_path = None
53+
for path in os.environ['PATH'].split(';'):
54+
# search heuristic: look for a path containing "cuda" and "bin" in this order.
55+
if re.search(r'cuda.*bin', path, re.IGNORECASE):
56+
cuda_bin_path = path
57+
break
58+
59+
if cuda_bin_path:
60+
os.add_dll_directory(cuda_bin_path)
61+
6262
# Check CUDA availability without importing CUDA pybind symbols to
6363
# prevent "symbol already registered" errors if first import fails.
64-
_pybind_cuda = load_cdll(
64+
_pybind_cuda = CDLL(
6565
str(next((Path(__file__).parent / "cuda").glob("pybind*"))))
6666
if _pybind_cuda.open3d_core_cuda_device_count() > 0:
6767
from open3d.cuda.pybind import (
@@ -212,4 +212,4 @@ def _jupyter_nbextension_paths():
212212

213213
if sys.platform == "win32":
214214
_win32_dll_dir.close()
215-
del os, sys, CDLL, load_cdll, find_library, Path, warnings, _insert_pybind_names
215+
del os, sys, CDLL, find_library, Path, warnings, _insert_pybind_names

0 commit comments

Comments
 (0)