To create a simple example how to extend Python with C++ extensions.
python3-devorpython3-develpython development packageC++compiler
python3 setup.py build will build the C++ extension.
python3 setup.py install will build and install it.
You can use --user flag to install to the Python user install directory.
First, install the extension. Then you can use it like this:
import cpp_python_extension
print(cpp_python_extension.sieve_of_eratosthenes(11))This will print all the prime numbers from 1 to 11 (inclusive).
python3 -m pytest test_benchmark.py --verbose
setup.py-setuptoolsfile to easily build and install the extensionsieve.h- header file with declaration ofSieveOfEratosthenesfunctionsieve.cpp- implementation filesieve_python_wrapper.cpp- wrapper aroundSieveOfEratosthenesfunction to createcpp_python_extensionmoduletest_benchmark.py- simple file to benchmark the extension
ExtendingPythonTalk project