1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python package with C++ codebase

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I wrote a scientific C++ simulation that I would like to wrap in a Python package so that users can easily install it via pip and run it from within Python.

    I am new to packaging and I need advice on which approach to choose. The packaging best-practices seem to be subject to on-going change, and the added complexity that the C++ part should run on any architecture leaves me a bit overwhelmed.

    My current setup is a C++ compiled binary that is run from within Python via subprocess.Popen.On top of that, there are a few added Python files containing pure Python data processing utility.

    I understand that there are two possible approaches:


    1. Ship the package with compiled binaries. This can be achieved by using setuptools and cibuildwheels to create wheels for any system architecture.


    2. Have the installation process compile the C++ source (by adding a CMake file to the package) such that I don't need to bother with shipping system-specific files/binaries.

    As the package is still being developed, I think going with option 2) would be better for now.

    On a sidenote, rather than running a binary from within Python, I also tried using C++ bindings like PyBind11 and Nanobind, but I observed a significant efficiency drop compared to calling a binary via subprocess.Popen .

    Any comments on what the best approach is for this endeavour or helpful links to up-to-date guidance would be appreciated.

    Continue reading...

Compartilhe esta Página