Search code examples
pythonc++packagepybind11xtensor

how to create a python package created using pybind?


I created a miniconda environment using the following command:

conda create -n build_a_python_cpp_module xtensor-python -c conda-forge

Activated the environment and created a cookiecutter project for x-tensor (a C++ library for fast array computations like NumPy) in the project folder.

pip3 install cookiecutter
cookiecutter https://github.com/QuantStack/xtensor-python-cookiecutter.git

After the project was created, I wrote a simple program to count the commas and new lines in a file in both C++ and python to compare the performance difference.

I bound the function in C++ using pybind11 and ran

python3 setup.py install

Importing the package and running the C++ method inside it using the python binding works but I want to know:

What should I do to be able to package it and transfer the code to another machine?


Solution

  • You should be able to run python setup.py bdist_wheel. This will create a wheel that you can upload on pypi.

    You can test if it works with pip install dist/name_of_your_wheel before uploading it.

    Let me know if you encounter any issue