macOS: How to build a wrapper that works with different kinds of Python installations (official, Homebrew, ...)? #5077
-
I have built a wrapper library using Python installed with the official Installer. Thus, the .so file contains the following information
Now i would like to use this wrapper from a Homebrew Python installation but even when running What is the recommended way of building and distributing such wrapper libraries for macOS? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Do not link to Python (except on Windows). See https://pybind11.readthedocs.io/en/stable/compiling.html and our three example repos, which include build systems, wheels, and cibuildwheel. |
Beta Was this translation helpful? Give feedback.
You need to build per Python version. If you use the Limited ABI, which pybind11 doesn't support yet, and nanobind only supports for 3.12+, then you can build once and reuse on later Python versions (this is true for all OS's). You use undefined symbols on linux and macOS, though macOS is better if you can generate the symbol list and give it to the linker. nanobind does this, but pybind11 doesn't currently. And windows you have to give it to the linker, though I think the linker uses the symbol list but doesn't make a hard link. It helps the linker to know if there are undefined symbols when loaded from Python, but you don't want to make a hard link, otherwise you'll depend on the exact …