Search code examples
pythonpybind11stub

No Module Named error when trying to run pybind11-stubgen


I've been scratching my head (googling, chatgpt-ing) trying to figure out why I can't generate a pyi file for a pybind module with pybind11-stubgen. I did this about a year ago successfully but can't remember the specifics.

I'm getting a "No Module Named {my-pybind-module}" error when I try running pybind11-stubgen in a terminal window.

Then it occurred to me (and it rings a memory bell) that maybe the pybind module needs to be "installed" in my environment in order for this to work. These are ad hoc pybind11 modules I'm building - I can successfully import and use them from python, but I wouldn't normally install them in my environment.

Do I need to do this in order to run pybind11-stubgen successfully? And if so, what is the simplest and easiest way to do this? These are just private modules, rebuilt very frequently during development - putting some together some kind of package that can be used with pip seems like overkill.


Solution

  • You might have to ensure the troubling module is properly installed.

    However if you are working with dev version of the package and it's not installed you might need to set up some env variables to make python import your module.

    Not sure what your specific platform is but on Linux it's PYTHONPATH/LD_LIBRARY_PATH. See this similar issue.