How to build a Python C Extension so I can import it from a module

Just change Extension(‘c_extension’, …) to Extension(‘foo.bar.c_extension’, …) You will need __init__.py files in each of the foo and bar directories, as usual. To have these packaged with the module in your setup.py, you need to add packages = [‘foo’, ‘foo.bar’], to your setup() call, and you will need the directory structure setup.py foo/ __init__.py bar/ … 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

Running Cython in Windows x64 – fatal error C1083: Cannot open include file: ‘basetsd.h’: No such file or directory

In case anyone is currently (2017) facing same error with visual C++ 2015 tools, launch setup again and also select windows 8.1 / 10 SDK depending upon your OS. This will fix basestd.h error. If it is still not working, try launching build tools from: C:\Program Files (x86)\Microsoft Visual C++ Build Tools. Another alternative would … Read more