C wrapper

S

Sheldon

Hi,

Can anyone give me some idea as to what this error means?

"ImportError: dynamic module does not define init function "

I am new at this and there is still a lot to learn.

Any help is appreciated,

/Sheldon
 
F

Farshid Lashkari

Sheldon said:
Can anyone give me some idea as to what this error means?

"ImportError: dynamic module does not define init function "

I am new at this and there is still a lot to learn.

Any help is appreciated,

Take a look at the documentation for creating extension modules,
especially the following page:

http://docs.python.org/ext/methodTable.html

"The initialization function must be named initname(), where name is the
name of the module, and should be the only non-static item defined in
the module file"

-Farshid
 
S

Sheldon

Farshid Lashkari skrev:
Take a look at the documentation for creating extension modules,
especially the following page:

http://docs.python.org/ext/methodTable.html

"The initialization function must be named initname(), where name is the
name of the module, and should be the only non-static item defined in
the module file"

-Farshid

This function is there and is called init_mymodule() but I have other
functions that are not static.
Could this be the cause?

/Sheldon
 
R

Robert Kern

Sheldon said:
This function is there and is called init_mymodule() but I have other
functions that are not static.

Is the module's name "_mymodule"? Or is it "mymodule"?

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
S

Sheldon

Robert Kern skrev:
Is the module's name "_mymodule"? Or is it "mymodule"?

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Here is the file/module name: _msgpps_functions.c
Here is the initfunction:

PyMODINIT_FUNC init_msgpps_functions(void) {
PyObject* m;
m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods);
ErrorObject = PyString_FromString("_msgpps_functions.error");
if(ErrorObject == NULL || \
PyDict_SetItemString(PyModule_GetDict(m),"error",ErrorObject)!=0)
{
Py_FatalError("Can't define _msgpps_functions.error");
import_array();
} /* access to Numeric PyArray functions */
}


I have not main() function in the file. Instead the main function is
called the same name:

static PyObject* _msgpps_functions(PyObject* self, PyObject* args)

Now I am new at this and I have been reading anything I can find. The
only thing that is out of place is the part which I didn't include:

/* Initialize the Python interpreter. Required. */
Py_Initialize();

/* Add a static module */
initspam();
because I still don't understand this part.

/sheldon
 
G

Gabriel Genellina

This function is there and is called init_mymodule() but I have other
functions that are not static.
Could this be the cause?

For a module called foo.c the initialization function must be called
initfoo (*not* init_foo)
And what are those non-static functions used for? The *only* purpose
of your module should be to provide the Python bindings...


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
S

Sheldon

Hi,
For a module called foo.c the initialization function must be called
initfoo (*not* init_foo)

Ok, I fixed this part. Thanks

And what are those non-static functions used for? The *only* purpose
of your module should be to provide the Python bindings...

I wrote the C module to do some number crunching. Now I just need to
"connect" it to my python program. Should the initmsgpps_functions() be
the only function in the file? Then how do I "connect" my C module to
my Python program?

/Sheldon
 
G

Gabriel Genellina

Here is the file/module name: _msgpps_functions.c
Here is the initfunction:

PyMODINIT_FUNC init_msgpps_functions(void) {
PyObject* m;
m=Py_InitModule("_msgpps_functions",_msgpps_functionsMethods);
ErrorObject = PyString_FromString("_msgpps_functions.error");
if(ErrorObject == NULL || \
PyDict_SetItemString(PyModule_GetDict(m),"error",ErrorObject)!=0)
{
Py_FatalError("Can't define _msgpps_functions.error");
import_array();
} /* access to Numeric PyArray functions */
}


I have not main() function in the file. Instead the main function is
called the same name:

static PyObject* _msgpps_functions(PyObject* self, PyObject* args)

Now I am new at this and I have been reading anything I can find. The
only thing that is out of place is the part which I didn't include:

/* Initialize the Python interpreter. Required. */
Py_Initialize();

/* Add a static module */
initspam();
because I still don't understand this part.

Are you *extending* Python with a new module written in C (you should
be using the first part),
or *embedding* python inside your application, mainly written in C
(you would use something like the last code).


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 
S

Sheldon

Gabriel Genellina skrev:
Are you *extending* Python with a new module written in C (you should
be using the first part),
or *embedding* python inside your application, mainly written in C
(you would use something like the last code).


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

Ok,

This I have done but still, the same error message. :(
 
G

Gabriel Genellina

I wrote the C module to do some number crunching. Now I just need to
"connect" it to my python program. Should the initmsgpps_functions() be
the only function in the file? Then how do I "connect" my C module to
my Python program?

Read again the docs but have in mind that you are *extending* the
interpreter with a new module - disregard the references to
*embedding* Python (even if they appear in a section about
extending!). I can see your confusion reading
http://docs.python.org/ext/methodTable.html

That is, you *don't* write a main() function, and you *don't* invoke
Py_Initialize; just write your initXXX() function.


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top