sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
232 stars 47 forks source link

Generating and using a .pyi without "installing" the module in question? #227

Closed jandyman closed 3 weeks ago

jandyman commented 3 weeks ago

It seemed to me that from the documentation that I would just open a terminal and say the following to generate the pyi file:

pybind11-stubgen pybind_streaming

Provided that the module is in the current directory. But I get:

ModuleNotFoundError: No module named 'pybind_streaming'

The .so is in the current folder and the full filename is pybind_streaming.cpython-312-darwin.so

It seems I don't understand something very basic. What can I read to straighten my head out? Can .pyi files not be generated for modules that are not installed? I'm still developing the pybind module so it doesn't make sense to install it yet.

I don't use cmake to build my pybind11 modules anymore, due to a weird cmake bug on MacOS. I now use a makefile. That is when all my autocompletion stopped working in ipython, and I'm assuming it has to do with a missing pyi file based on a stack overflow inquiry.

sizmailov commented 3 weeks ago

The module must be importable.

You can test it using the following command to test your setup.

python -c "import pybind_streaming"

Try setting PYTHONPATH before running the command, e.g.:

export PYTHONPATH="$PWD"
pybind11-stubgen pybind_streaming