Skip to content

add current directory to sys.path for Windows module resolution#299

Open
MohammadRaziei wants to merge 1 commit intopybind:mainfrom
MohammadRaziei:main
Open

add current directory to sys.path for Windows module resolution#299
MohammadRaziei wants to merge 1 commit intopybind:mainfrom
MohammadRaziei:main

Conversation

@MohammadRaziei
Copy link
Copy Markdown

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 ✓

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.
@sizmailov
Copy link
Copy Markdown
Collaborator

#77 (comment)

@MohammadRaziei
Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants