add current directory to sys.path for Windows module resolution#299
Open
MohammadRaziei wants to merge 1 commit intopybind:mainfrom
Open
add current directory to sys.path for Windows module resolution#299MohammadRaziei wants to merge 1 commit intopybind:mainfrom
MohammadRaziei wants to merge 1 commit intopybind:mainfrom
Conversation
Insert the current working directory at the beginning of sys.path before processing modules. This ensures that local modules can be resolved correctly when pybind11-stubgen is run, preventing import errors for modules located in the current directory.
Collaborator
Author
|
Why do you think this is not a good idea?? I believe that this is a necessary option, and I was shocked when I found that this was missed. |
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.
On Windows, when running pybind11-stubgen from a build directory
(e.g., via CMake), the compiled module (.pyd file) cannot be found
because it's not in Python's search path.
This fix adds the current working directory to sys.path before
importing the module, ensuring compatibility with Windows builds
where the module exists in the build directory.
Example on Windows:
build/src/mymodule.cp311-win_amd64.pyd ← exists but not found
Without this fix:
ModuleNotFoundError: No module named 'mymodule'
With this fix:
Module imports successfully ✓