Fix Open3D import crash when pybind stub directories exist (#7481)#7510
Open
Iyanuoluwa007 wants to merge 1 commit into
Open
Fix Open3D import crash when pybind stub directories exist (#7481)#7510Iyanuoluwa007 wants to merge 1 commit into
Iyanuoluwa007 wants to merge 1 commit into
Conversation
|
Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes a runtime crash in Open3D’s Python import path when pybind11-stubgen (or similar tooling) leaves pybind/ stub directories alongside the compiled extension, causing ctypes.CDLL to attempt to load a directory.
Changes:
- Filter
Path.glob("pybind*")results to files-only before passing toctypes.CDLL(CPU path). - Apply the same files-only filtering for the CUDA
ctypes.CDLLload used during CUDA availability checks.
Comment on lines
+39
to
+42
| CDLL(str(next( | ||
| p for p in (Path(__file__).parent / "cpu").glob("pybind*") | ||
| if p.is_file() | ||
| ))) |
Comment on lines
+67
to
+70
| _pybind_cuda = CDLL(str(next( | ||
| p for p in (Path(__file__).parent / "cuda").glob("pybind*") | ||
| if p.is_file() | ||
| ))) |
Comment on lines
+39
to
43
| CDLL(str(next( | ||
| p for p in (Path(__file__).parent / "cpu").glob("pybind*") | ||
| if p.is_file() | ||
| ))) | ||
| except StopIteration: |
Comment on lines
+39
to
+42
| CDLL(str(next( | ||
| p for p in (Path(__file__).parent / "cpu").glob("pybind*") | ||
| if p.is_file() | ||
| ))) |
Comment on lines
+67
to
+70
| _pybind_cuda = CDLL(str(next( | ||
| p for p in (Path(__file__).parent / "cuda").glob("pybind*") | ||
| if p.is_file() | ||
| ))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
Fixes #7481
Related issue:
#7481
Motivation and Context
Checklist:
python util/check_style.py --applyto apply Open3D code styleto my code.
updated accordingly.
results (e.g. screenshots or numbers) here.
Description
Problem
When generating Python stubs using
pybind11-stubgen, apybind/directory is created inside the Open3D package (e.g.open3d/cpu/pybind/oropen3d/cuda/pybind/).The current implementation in
open3d/__init__.pylocates the compiled Python extension using:However,
glob("pybind*")may return both:pybind/)pybind*.so,pybind*.dll, etc.)Because
next()does not filter by type, the directory may be selected first.This leads to a runtime crash when ctypes attempts to load a directory:
Root Cause
Path.glob("pybind*")matches both files and directoriesCDLLFix
Filter glob results to ensure only valid shared library files are used: