No module named 'pybind11' when using poetry

125 Views Asked by At

Used pybind11 in the past without issue pulled in as a submodule and used via cmake. Now working on another project that uses poetry, and so wanted to make everything poetry-centric.

Trying to build this simple example project https://github.com/octavifs/poetry-pybind11-integration results in the failure

Preparing build environment with build-system requirements poetry-core>=1.0.0
Building poetry-pybind11-integration (0.1.0)
Traceback (most recent call last):
  File "/blah/poetry-pybind11-integration/build.py", line 1, in <module>
    from pybind11.setup_helpers import Pybind11Extension, build_ext
ModuleNotFoundError: No module named 'pybind11'

where the first line of build.py is from pybind11.setup_helpers import Pybind11Extension, build_ext and pybind11 is listed in the toml.

Why?

1

There are 1 best solutions below

0
On BEST ANSWER

There is an un-merged (at the time of writing) pull request that holds the solution. In the build settings in the config, build system should be adjusted as shown

[build-system]
# requires = ["poetry-core>=1.0.0"]
requires = [
    "poetry-core>=1.1.0",
    "setuptools>=65.4.1",
    "pybind11>=2.8.0"
]
build-backend = "poetry.core.masonry.api"

EDIT: It turns out there were more changes than this needed so I've set out a simple example project here for anyone stumbling upon this in the future.