I am trying to reproduce the following tutorial https://csl.name/post/c-functions-python/ .
The extension of My Python in C ++ is as follows:
#include <Python.h> static PyObject* py_myFunction(PyObject* self, PyObject* args) { char *s = "Hello from C!"; return Py_BuildValue("s", s); } static PyObject* py_myOtherFunction(PyObject* self, PyObject* args) { double x, y; PyArg_ParseTuple(args, "dd", &x, &y); return Py_BuildValue("d", x*y); } static PyMethodDef extPy_methods[] = { {"myFunction", py_myFunction, METH_VARARGS}, {"myOtherFunction", py_myOtherFunction, METH_VARARGS}, {NULL, NULL} }; void initextPy(void) { (void) Py_InitModule("extPy", extPy_methods); }
I use the following setup.py :
from distutils.core import setup, Extension setup(name='extPy', version='1.0', \ ext_modules=[Extension('extPy', ['extPy.cpp'])])
After calling python setup.py install the .so file seems to be in the right place.
But when I try to use this extension with import extPy , I get an error:
ImportError: dynamic module does not define init function
What am I missing here? Thanks for the help.
c ++ python
P alcove
source share