C wrapper

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sheldon

    #1

    C wrapper

    Hi,

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

    "ImportErro r: 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

  • Farshid Lashkari

    #2
    Re: C wrapper

    Sheldon wrote:
    Can anyone give me some idea as to what this error means?
    >
    "ImportErro r: 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:



    "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

    Comment

    • Sheldon

      #3
      Re: C wrapper


      Farshid Lashkari skrev:
      Sheldon wrote:
      Can anyone give me some idea as to what this error means?

      "ImportErro r: 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:
      >

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

      Comment

      • Robert Kern

        #4
        Re: C wrapper

        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

        Comment

        • Sheldon

          #5
          Re: C wrapper


          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_functio ns.c
          Here is the initfunction:

          PyMODINIT_FUNC init_msgpps_fun ctions(void) {
          PyObject* m;
          m=Py_InitModule ("_msgpps_funct ions",_msgpps_f unctionsMethods );
          ErrorObject = PyString_FromSt ring("_msgpps_f unctions.error" );
          if(ErrorObject == NULL || \
          PyDict_SetItemS tring(PyModule_ GetDict(m),"err or",ErrorObject )!=0)
          {
          Py_FatalError(" Can't define _msgpps_functio ns.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_functio ns(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

          Comment

          • Gabriel Genellina

            #6
            Re: C wrapper

            At Tuesday 7/11/2006 17:10, Sheldon wrote:
            Take a look at the documentation for creating extension modules,
            especially the following page:



            "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

            Comment

            • Sheldon

              #7
              Re: C wrapper


              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_func tions() be
              the only function in the file? Then how do I "connect" my C module to
              my Python program?

              /Sheldon

              Comment

              • Gabriel Genellina

                #8
                Re: C wrapper

                At Tuesday 7/11/2006 17:27, Sheldon wrote:
                >Here is the file/module name: _msgpps_functio ns.c
                >Here is the initfunction:
                >
                >PyMODINIT_FU NC init_msgpps_fun ctions(void) {
                PyObject* m;
                m=Py_InitModule ("_msgpps_funct ions",_msgpps_f unctionsMethods );
                ErrorObject = PyString_FromSt ring("_msgpps_f unctions.error" );
                if(ErrorObject == NULL || \
                PyDict_SetItemS tring(PyModule_ GetDict(m),"err or",ErrorObject )!=0)
                >{
                Py_FatalError(" Can't define _msgpps_functio ns.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_functio ns(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

                Comment

                • Sheldon

                  #9
                  Re: C wrapper


                  Gabriel Genellina skrev:
                  At Tuesday 7/11/2006 17:27, Sheldon wrote:
                  >
                  Here is the file/module name: _msgpps_functio ns.c
                  Here is the initfunction:

                  PyMODINIT_FUNC init_msgpps_fun ctions(void) {
                  PyObject* m;
                  m=Py_InitModule ("_msgpps_funct ions",_msgpps_f unctionsMethods );
                  ErrorObject = PyString_FromSt ring("_msgpps_f unctions.error" );
                  if(ErrorObject == NULL || \
                  PyDict_SetItemS tring(PyModule_ GetDict(m),"err or",ErrorObject )!=0)
                  {
                  Py_FatalError(" Can't define _msgpps_functio ns.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_functio ns(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. :(

                  Comment

                  • Gabriel Genellina

                    #10
                    Re: C wrapper

                    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_func tions() 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


                    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

                    Comment

                    Working...