[Python] vscode not autocompleting python from module made with pybind11

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I have a python module named relatpy.cpython-38-x86_64-linux-gnu.so that I created using pybind11 with a custom made C++ library. When I import this module in the terminal using something like ipython I get functional autocompletion like the figure shows.

    [​IMG]

    However in vscode I don't get any autocompletion, I just get the message Import "relatpy" could not be resolved. The python file that imports this module can still be run just fine in vscode, just no autocompletion.

    Do I have to add this module to my PYTHONPATH or how do I go about doing this? This module is also rebuilt pretty often so is there a way to get autocompletion to work even if the module changes?

    I'm using pylance as the python language server in vscode.

    I created the pybind11 module using the following CMakeLists.txt:

    project(relatpy)

    find_package(pybind11 REQUIRED)

    file(GLOB SOURCES "../relativity/src/*.cpp")
    file(GLOB HEADERS "../relativity/include/*.h")
    file(GLOB BINDINGS "*.cpp")

    pybind11_add_module(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${BINDINGS})

    set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PYTHON_DIR})

    Continue reading...

Compartilhe esta Página