Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > C wrapper

Reply
Thread Tools

C wrapper

 
 
Sheldon
Guest
Posts: n/a
 
      11-07-2006
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

 
Reply With Quote
 
 
 
 
Farshid Lashkari
Guest
Posts: n/a
 
      11-07-2006
Sheldon wrote:
> 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
 
Reply With Quote
 
 
 
 
Sheldon
Guest
Posts: n/a
 
      11-07-2006

Farshid Lashkari skrev:

> Sheldon wrote:
> > 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


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

/Sheldon

 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      11-07-2006
Sheldon wrote:

> 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

 
Reply With Quote
 
Sheldon
Guest
Posts: n/a
 
      11-07-2006

Robert Kern skrev:

> Sheldon wrote:
>
> > 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


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_functi onsMethods);
ErrorObject = PyString_FromString("_msgpps_functions.error");
if(ErrorObject == NULL || \
PyDict_SetItemString(PyModule_GetDict(m),"error",E rrorObject)!=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

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      11-07-2006
At Tuesday 7/11/2006 17:10, Sheldon wrote:

> > 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?


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
 
Reply With Quote
 
Sheldon
Guest
Posts: n/a
 
      11-07-2006

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

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      11-07-2006
At Tuesday 7/11/2006 17:27, Sheldon wrote:

>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_functi onsMethods);
> ErrorObject = PyString_FromString("_msgpps_functions.error");
> if(ErrorObject == NULL || \
> PyDict_SetItemString(PyModule_GetDict(m),"error",E rrorObject)!=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
 
Reply With Quote
 
Sheldon
Guest
Posts: n/a
 
      11-07-2006

Gabriel Genellina skrev:

> At Tuesday 7/11/2006 17:27, Sheldon wrote:
>
> >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_functi onsMethods);
> > ErrorObject = PyString_FromString("_msgpps_functions.error");
> > if(ErrorObject == NULL || \
> > PyDict_SetItemString(PyModule_GetDict(m),"error",E rrorObject)!=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


Ok,

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

 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      11-07-2006
At Tuesday 7/11/2006 17:43, Sheldon wrote:

> > 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?


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrapper on magic line? Nilsson Mats Perl 0 12-09-2003 02:48 PM
Deployment of DTSPKG.DLL wrapper Marlene Arauz ASP .Net 0 11-10-2003 07:50 PM
wrapper function for uploading files Brian Pittman ASP .Net 3 07-30-2003 06:09 PM
Re: Coding a c# wrapper class to unmanaged C++ program, need some guidance Brendan Duffy ASP .Net 0 07-25-2003 12:49 AM
Anyone know of a ASP.NET wrapper for HTMLTidy? Showjumper ASP .Net 2 07-04-2003 01:26 AM



Advertisments