Ich versuche, das folgende Tutorial https://csl.name/post/c-functions-python/ zu reproduzieren.ImportError: dynamisches Modul definiert nicht Init-Funktion
Meine Python-Erweiterung in C++ wie folgt aussieht:
#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);
}
ich folgende setup.py bin mit:
from distutils.core import setup, Extension
setup(name='extPy', version='1.0', \
ext_modules=[Extension('extPy', ['extPy.cpp'])])
Nachdem es mit python setup.py install
die .so-Datei Aufruf scheint an der richtigen Stelle sein.
Aber wenn ich versuche, diese Erweiterung zu verwenden, mit import extPy
bekomme ich den Fehler:
Import: dynamische Modul wird nicht definiert, init-Funktion
Was bin ich hier fehlt? Danke für die Hilfe.
Dies hat seinen Zweck erfüllt. Vielen Dank. –