Import a .so file from Django
Question: I have a C++ code

    
    
    #include <Python.h>
    
    static PyObject* py_veripy(PyObject* self, PyObject* args){
    
        /* BODY */
        return Py_BuildValue("i", 1);
    
    }
    
    // Bind Python function names to our C functions
    static PyMethodDef veripy_methods[] = {
        {"veripy", py_veripy, METH_VARARGS},
        {NULL, NULL}
    };
    
    // Python calls this to let us initialize our module
    extern "C" void initveripy(){
        (void) Py_InitModule("veripy", veripy_methods);
    }
    

I have compiled it and created a .so file. I want to use this library in one
of my Django app, but I am confused as to where to keep this library in my
directory. I have tried keeping it with the code, obviously, but it doesn't
seem to find it. I found
[this](http://www.dreamincode.net/forums/topic/252650-making-importing-and-
using-a-c-library-in-python-linux-version/) tutorial similar to my case, but
the C++ code there doesn't have Python.h included in it. Please help.


Answer: I think that you should create a setup.py file, so that this compiles your
library and put it somewhere.

For example, here an example of a setup.py file that I used for a personal
project:

    
    
    from setuptools import setup, Extension
    
    setup(
          name="modulename", 
          version="0.1",
          test_suite = "nose.collector",
          author='<author name>',
          setup_requires=['nose>=0.11'],
          description="My super module implementation",
          ext_modules=[Extension("modulename", ["src/mysupermodule.c"])]
    )
    

This will generate a 'build/' folder, but of course you can find more about
setuptools on [the official documentation
page](https://pythonhosted.org/setuptools/setuptools.html).

