C wrapper

Discussion in 'Python' started by Sheldon, Nov 7, 2006.

  1. Sheldon

    Sheldon Guest

    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
    Sheldon, Nov 7, 2006
    #1
    1. Advertising

  2. 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
    Farshid Lashkari, Nov 7, 2006
    #2
    1. Advertising

  3. Sheldon

    Sheldon Guest

    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
    Sheldon, Nov 7, 2006
    #3
  4. Sheldon

    Robert Kern Guest

    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
    Robert Kern, Nov 7, 2006
    #4
  5. Sheldon

    Sheldon Guest

    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_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
    Sheldon, Nov 7, 2006
    #5
  6. 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
    Gabriel Genellina, Nov 7, 2006
    #6
  7. Sheldon

    Sheldon Guest

    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
    Sheldon, Nov 7, 2006
    #7
  8. 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_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
    Gabriel Genellina, Nov 7, 2006
    #8
  9. Sheldon

    Sheldon Guest

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


    Ok,

    This I have done but still, the same error message. :(
    Sheldon, Nov 7, 2006
    #9
  10. 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
    Gabriel Genellina, Nov 7, 2006
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brendan Duffy
    Replies:
    0
    Views:
    3,986
    Brendan Duffy
    Jul 25, 2003
  2. Nilsson Mats

    Wrapper on magic line?

    Nilsson Mats, Dec 9, 2003, in forum: Perl
    Replies:
    0
    Views:
    602
    Nilsson Mats
    Dec 9, 2003
  3. Showjumper
    Replies:
    2
    Views:
    445
    Showjumper
    Jul 4, 2003
  4. Brian Pittman

    wrapper function for uploading files

    Brian Pittman, Jul 30, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    482
    Kevin Spencer
    Jul 30, 2003
  5. Marlene Arauz

    Deployment of DTSPKG.DLL wrapper

    Marlene Arauz, Nov 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    528
    Marlene Arauz
    Nov 10, 2003
Loading...

Share This Page