To create a simple example how to extend Python with C++ extensions.
python3-dev
orpython3-devel
python 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
-setuptools
file to easily build and install the extensionsieve.h
- header file with declaration ofSieveOfEratosthenes
functionsieve.cpp
- implementation filesieve_python_wrapper.cpp
- wrapper aroundSieveOfEratosthenes
function to createcpp_python_extension
moduletest_benchmark.py
- simple file to benchmark the extension
ExtendingPythonTalk project