SWIG: ImportError: dynamic module does not define init function

Ignacio Vazquez-Abrams ignacio at openservices.net
Mon Sep 17 17:16:54 EDT 2001


On Mon, 17 Sep 2001, Louis Luangkesorn wrote:

> Ok, I'm having a bit of a clue problem.  Which modules should I be looking at?
> I've been searching through the example code that comes with SWIG 1.3.7 as well as
> the Python source on SourceForge. What is supposed to go into the initcnumint()
> function?  There seem to be a couple of different things that can be done.  One
> was from mathmodule.c
>
> initmath(void)
> {
>         PyObject *m, *d, *v;
>
>         m = Py_InitModule3("math", math_methods, module_doc);
>         d = PyModule_GetDict(m);
> /* stuff */
> }
>
> Another one is from newmodule.c
>
> initnew(void)
> {
>         Py_InitModule4("new", new_methods, new_doc, (PyObject *)NULL,
>                        PYTHON_API_VERSION);
> }
>
> So, what are Py_InitModule3 and Py_InitModule4?  Which one should I be using? Do
> any of the Python (or SWIG) .c files have a good model to use to implement a
> init<module>() function?  Looked at the Extending and Embedding docs also but I
> think I missed it. Thanks.

That's because the functions are very well hidden in the Python/C API
Reference Manual:

  http://www.python.org/doc/current/api/newTypes.html

Basically, if you can do without a docstring or if you put it in the module
dictionary manually you can use Py_InitModule(), otherwise use
Py_InitModule3(). I don't know of too many instances where you'll need
Py_InitModule4().

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list