Import C module not working in Python 3 -
i tried write module python using c-api module wouldn't import. problem persists minimal example:
#include <python.h> #include <stdio.h> static pymethoddef capmethods[] = { {null, null, 0, null} /* sentinel end of array*/ }; static struct pymoduledef capmodule = { pymoduledef_head_init, "puzzler", /* name of module */ null, /* module documentation, may null */ -1, /* -1 if 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 i'm missing obvious can't tell is. completeness here setup.py:
from distutils.core import setup, extension cap = extension( 'puzzler', sources = ['minimal.c'], ) setup( name = 'puzzlesolver', version = '1.0', description = 'this demo package', ext_modules = [cap]) if knows wrong or wants additional information setup, feel free ask in comments. 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 python console output when try out:
>>> import puzzler initializing... minimal failed! traceback (most recent call last): file "<stdin>", line 1, in <module> systemerror: initialization of puzzler raised unreported exception
Comments
Post a Comment