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

The error also occurs, when using boost::python, if the module name is different to the compiled .so file name. For example: hello.cpp #include <boost/python/module.hpp> #include <boost/python/def.hpp> using namespace std; using namespace boost::python; int helloWorld(){ cout << “Hello world!” << endl; return 0; } BOOST_PYTHON_MODULE(libhello) { def(“hello_world”, helloWorld); } compilation command: g++ -fpic -shared -o libfoo.so … Read more

Create an object using Python’s C API

Call PyObject_New(), followed by PyObject_Init(). EDIT: The best way is to call the class object, just like in Python itself: /* Pass two arguments, a string and an int. */ PyObject *argList = Py_BuildValue(“si”, “hello”, 42); /* Call the class object. */ PyObject *obj = PyObject_CallObject((PyObject *) &pyfoo_T, argList); /* Release the argument list. */ … Read more

PyEval_InitThreads in Python 3: How/when to call it? (the saga continues ad nauseam)

Your understanding is correct: invoking PyEval_InitThreads does, among other things, acquire the GIL. In a correctly written Python/C application, this is not an issue because the GIL will be unlocked in time, either automatically or manually. If the main thread goes on to run Python code, there is nothing special to do, because Python interpreter … Read more