This project includes several examples of how to embed Python in C++ with CMake. Please be sure that this project was only built and tested on MacOS.
- MacOS 12.0.1
- Miniconda 4.12.0
- CMake 3.22.3
Miniconda or Anaconda is required.
(base)% conda create -n ep python=3
(base)% conda activate ep
(ep)% pip install numpy
# before installing gcc, Xcode was already installed which was not sure to affect compilation of the source code.
(ep)% brew install git cmake gcc
(ep)% git clone https://github.com/supertigim/EmbeddingPython3inCppwithCMake.git
(ep)% cd EmbeddingPython3inCppwithCMake
(ep)% sh ./build_all.sh
# python related logs when running cmake
Python_FOUND:TRUE
Python_VERSION:3.10.4
Python_Development_FOUND:TRUE
Python_LIBRARIES:/usr/local/Caskroom/miniconda/base/envs/ep/lib/libpython3.10.dylib
Python_INCLUDE_DIRS:/usr/local/Caskroom/miniconda/base/envs/ep/include/python3.10
Then, go to ./build directory and run embedding-python-ex1 ~ 8
- Embedding Python program in a C/C++ code
- C/C++ 결합, Embedded Python
- Is there any benefit to using Py_DECREF instead of Py_XDECREF for Python C Extensions?
- 16. Embedding Python in C/C++
- Parsing arguments and building values
MIT