ImportError: dynamic module does not define init function
NickName:P Alcove Ask DateTime:2015-01-20T16:38:11

ImportError: dynamic module does not define init function

I am trying to reproduce the following tutorial https://csl.name/post/c-functions-python/.

My Python extension in C++ looks like:

#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 am using the following setup.py:

from distutils.core import setup, Extension
setup(name='extPy', version='1.0',  \
ext_modules=[Extension('extPy', ['extPy.cpp'])])

After invoking it with 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 the Error:

ImportError: dynamic module does not define init function

What am I missing here? Thanks for Help.

Copyright Notice:Content Author:「P Alcove」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/28040833/importerror-dynamic-module-does-not-define-init-function

More about “ImportError: dynamic module does not define init function” related questions

GAE ImportError: dynamic module does not define init function (init_mysql)

My staging GAE app throws the below err, File "/base/data/home/apps/foo156801/worker:20170301t222555.399535951340506041/lib/MySQLdb/__init__.py", line 19, in &lt;module&gt; import _mysql ImportErr...

Show Detail

ImportError: dynamic module does not define init function Naming is correct

While trying to build python bindings with C, I have the following #if PY_VERSION_HEX &gt;= 0x03000000 #define MOD_ERROR NULL #define MOD_INIT(name) PyObject* PyInit_##name(void) #define MOD_RETUR...

Show Detail

ImportError: dynamic module does not define init function (initlibpyuno)

I have installed Eclipse IDE with Python, I'm trying to setup an environment for writing some python scripts to automate Libre Office, I have made a script with just one line of code for now ("import

Show Detail

Pylibmc: ImportError: dynamic module does not define init function (init_pylibmc)

&gt;&gt;&gt; import pylibmc Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packa

Show Detail

Google AppEngine ImportError: dynamic module does not define init function (init_mysql)

I am getting this error when I deployed my python app with Flask on Google AppEngine. I will be grateful if someone help me. ps: My local server works like a charm File "/base/data/home/apps/s~dw...

Show Detail

ImportError dynamic module does not define init function (boost.python)

Thank you for see this topic. I tried to use boost.python but now this error happens. ImportError: dynamic module does not define init function (initlatticepy) I checked some questions in we...

Show Detail

What is the init function of a dynamic module in python?

I am getting the same error of these other two questions: ImportError: dynamic module does not define init function, but it does and Cython compiled C extension: ImportError: dynamic module does ...

Show Detail

ImportError: dynamic module does not define init function (initfizzbuzz)

I tried to compile fizzbuzz.c, in order to import it by python. For building fizzbuzz.c,I used python setup.py build_ext -i. After building it, I tried to import fizzbuzz.c but the error below occ...

Show Detail

ImportError: dynamic module does not define init function (initfizzbuzz)

I tried to compile fizzbuzz.c, in order to import it by python. For building fizzbuzz.c,I used python setup.py build_ext -i. After building it, I tried to import fizzbuzz.c but the error below occ...

Show Detail

Cython compiled C extension: ImportError: dynamic module does not define init function

I have just compiled part of my C library as an extension using Cython, as a "proof of concept". I managed to hack the code (const correctnes problems etc aside), to finally get an extension built.

Show Detail