I recently tried compiling some extension module I’ve been working for a while but the functions were no longer visible as they were before. I don’t know if there’s something I’ve missed cause I’m hitting a deadline and the anxiety is probably not helping. I tried reviewing changes in my code to see if there’s some error or change I introduced but still can’t find it. So I decided to write a basic extension function to compare and see if there’s any step I missed, but the test example was also showing the same behavior. So here’s the gist.
#define PY_T_SSIZE_CLEAN
#include <Python.h>
static PyObject*
test_func (PyObject* self, PyObject* args){
return PyLong_FromLong(10);
}
static PyMethodDef testmethods[] = {
{"testfunc",test_func,METH_VARARGS,"testing building ext"},
{NULL,NULL,0,NULL},
};
static struct
PyModuleDef TestModule = {
PyModuleDef_HEAD_INIT,
"test",
NULL,
-1,
testmethods,
};
PyMODINIT_FUNC
PyInit_test (void){
return PyModule_Create(&TestModule);
}
And the setup.py file is as below.
from setuptools import Extension,setup
module1 = Extension("test",
sources = ["test.c"]
)
setup (name = "testext",
version = "0.0.1",
description = "Testing...",
ext_modules = [module1]
)
so when I run python setup.py build_ext
, it builds the extension well, but then test_func
doesn’t appear in the extension.
>>>import test
>>>dir(test)
['__builtins__', '__cached__', '__doc__', '__file__','__loader__','__name__','__package__','__path__','__spec__']
>>>
I expected to see test_func
somewhere but can’t see it, and definitely can’t call it . So please help a frustrated soul meet a deadline