ImportError: dynamic module does not define init function (initfizzbuzz)

前端 未结 6 1235
生来不讨喜
生来不讨喜 2020-12-02 17:19

I tried to compile fizzbuzz.c, in order to import it by python. For building fizzbuzz.c,I used python setup.py build_ext -i.

A

6条回答
  •  悲哀的现实
    2020-12-02 17:47

    If you use python 3 then you need to have the following changes on your code,

    static struct PyModuleDef fizzbuzzModuleDef =
    {
        PyModuleDef_HEAD_INIT,
        "fizzbuzz", /* name of module */
        "",          /* module documentation, may be NULL */
        -1,          /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
        fizzbuzzModule_methods
    };
    
    PyMODINIT_FUNC PyInit_exmod(void) {
        return PyModule_Create(&fizzbuzzModuleDef);
    }
    

提交回复
热议问题