THe goal if this project is to interface C++ type with Python. Pybind11 is used for this interfacing feature. CMaek is used as build tool.
- This project is dependent on
pybind11
which is used in this project as a helper repository. - To clone and use pybind11 follow the following approach.
-
Go to the directory where
pybind11_cmake
project will be cloned and clone it with the following commandgit clone https://github.com/atifkarim/pybind11_cmake.git
-
Now keep
pybind11
in the same level of the current project. I have kept it in a common repository namedforked repo
mkdir forked_repo && cd forked_repo git clone https://github.com/pybind/pybind11.git
-
Finally the directory structure will be as like as follows
forked_repo/ └── pybind11 pybind11_cmake/
-
- To clone and prepare the repository by following current structure one can use this script
- Necessary python files are located in
example/py
dorectory - Used
pipreqs
module to createrequirements.txt
file to install necessary python moduleRemember, python module generated by pybind11 will not be counted here
- To use
pipreqs
pip install pipreqs
-> Source- Usage to create requirements.txt file:
pipreqs example/py/
To build the project necessary commands are written in run_project.sh
file which is located in the root
of the project. Execute it from the terminal by writing ./run_project.sh
.
This RTD Site is used to host the documentation of the project
This project is available in Docker. See this to use the docker image.
-
After preparing docker environment in your system, pull the docker image
docker pull atifkarim/test_image_pybind11_cmake
-
After pulling check images list by
docker images
command -
Now, run it using the following command
- Without interactive terminal
docker run atifkarim/test_image_pybind11_cmake
- Without interactive terminal
docker run -it atifkarim/test_image_pybind11_cmake bash
- Now, here you can see the file
prepare_project.sh
. - Make it executable by running
chmod +x prepare_project.sh
- Now run that file by using
./prepare_project.sh
. - This command will clone required repo and execute cpp, py file. Later, developer can do further development here.
- I have found the required repo by going to home directory
cd ~
- Now, here you can see the file
- Without interactive terminal
Here my planning is written regarding the project
-
Sometimes CMAKE faces issue while building project regarding finding appropriate python package. See this. Possible solution:
cmake .. -DPYTHON_EXECUTABLE=/usr/bin/python3.8
or,
cmake .. -DPYTHON_EXECUTABLE=$(which python)