Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C and Python, Py_InitModule method not found

Tags:

c++

python

c

I've been following some code examples on how to build a C module for Python, however it seems like Py_InitModule isn't defined anywhere.

Most sources say it's within the modsupport.h file, but the macro isn't defined there.

I'm using the includes given by the Win32 binaries download, and everything seems in check.

Any suggestions?

like image 513
DubyaDubyaDubyaDot Avatar asked May 02 '12 18:05

DubyaDubyaDubyaDot


1 Answers

Works for me on 2.7.2, Python 2 or 3? For example, for a module called Example:
Python 2:

/* Module entry point Python 2 */

PyMODINIT_FUNC initExample(void)
{
    (void) Py_InitModule("Example", ExampleMethods);
}

Python 3:

/* Module entry point Python 3 */

PyMODINIT_FUNC PyInit_Example(void)
{
    return PyModule_Create(&Example_module);
}
like image 186
cdarke Avatar answered Sep 30 '22 04:09

cdarke