Problem using python C API

Philip Semanchuk philip at
Fri Jan 16 15:58:54 CET 2009

On Jan 16, 2009, at 5:31 AM, shi dingan wrote:

> void initexample() {
>  PyObject *m;
>  m = Py_InitModule("example", exampleMethods);
> }
> When I try to import examplemodule, I obtain the following message:
>>>> import examplemodule
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> ImportError: dynamic module does not define init function
> (initexamplemodule)

Hi Marc,
The tutorial says, "The initialization function must be named  
initname(), where name is the name of the module". The error message  
you got is very accurate: "module does not define init function  
(initexamplemodule)". Since your module is called "examplemodule",  
Python is looking for a function called "initexamplemodule".

Change your build step to build a module called "example" and not  
"examplemodule" and I think you'll be OK.


More information about the Python-list mailing list