I tried to write a module for python using the c-api but the module wouldn't import. The problem persists for this minimal example:
#include <Python.h>
#include <stdio.h>
static PyMethodDef CAPMethods[] = {
{NULL, NULL, 0, NULL} /* Sentinel for end of array*/
};
static struct PyModuleDef CAPModule = {
PyModuleDef_HEAD_INIT,
"puzzler", /* name of module */
NULL, /* module documentation, may be NULL */
-1, /* -1 if the module keeps state in global variables. */
CAPMethods, /* Method table */
};
PyMODINIT_FUNC
PyInit_puzzler(void)
{
printf("Initializing...\n");
PyObject* module = PyModule_Create(&CAPModule);
if(module == NULL)
{
printf("Minimal Failed!\n");
Py_RETURN_NONE;
}
printf("Success!\n");
return module;
}
It feels like I'm missing something really obvious but I can't tell what it is. For completeness here is my setup.py:
from distutils.core import setup, Extension
CAP = Extension(
'puzzler',
sources = ['minimal.c'],
)
setup( name = 'PuzzleSolver',
version = '1.0',
description = 'This is a demo package',
ext_modules = [CAP])
If someone knows what I could do wrong or wants additional information about my setup, feel free to ask in the comments. I compile using python setup.py install
(Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
).
Here is the python console output when I try it out:
>>> import puzzler
Initializing...
Minimal Failed!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: initialization of puzzler raised unreported exception