Building Python modules in C++
<p>I've been trying to figure out how to build python modules with C++ but have been running into a lot of issues. I'm not trying to do anything fancy, I just want to get this to work. Here's the short version of my problem:</p>

<p>Trying to build the module via <code>python setup.py build</code> gives me <code>Unable to find vcvarsall.bat</code>.</p>

<p>Trying to use <code>python setup.py build -cmingw32</code> or <code>python setup.py build --compiler=mingw32</code> gives me:</p>

<pre><code>C:\Users\Windows 8\Desktop\Scripts\build test&gt;python setup.py build --compiler=mingw32
running build
running build_ext
Traceback (most recent call last):
  File "setup.py", line 8, in &lt;module&gt;
    ext_modules = [module1])
  File "C:\Python34\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python34\lib\distutils\command\build.py", line 126, in run
    self.run_command(cmd_name)
  File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
    cmd_obj.run()
  File "C:\Python34\lib\distutils\command\build_ext.py", line 308, in run
    force=self.force)
  File "C:\Python34\lib\distutils\ccompiler.py", line 1031, in new_compiler
    return klass(None, dry_run, force)
  File "C:\Python34\lib\distutils\cygwinccompiler.py", line 282, in __init__
    CygwinCCompiler.__init__ (self, verbose, dry_run, force)
  File "C:\Python34\lib\distutils\cygwinccompiler.py", line 126, in __init__
    if self.ld_version &gt;= "2.10.90":
TypeError: unorderable types: NoneType() &gt;= str()
</code></pre>

<p>Editing <code>cygwinccompiler.py</code> to change seemingly erroneous comparisons (there were more than the one shown above) to simply be <code>True</code> gives me:</p>

<pre><code>C:\Users\Windows 8\Desktop\Scripts\build test&gt;python setup.py build -cmingw32
running build
running build_ext
error: [WinError 2] The system cannot find the file specified
</code></pre>

<p>I'm using python 3.4.3</p>

<p>The code I was trying to use is given below, but I don't think that's where the problem lies. Any help is greatly appreciated.</p>

<p><strong>setup.py</strong></p>

<pre><code>from distutils.core import setup, Extension

module1 = Extension('test', sources = ['test.cpp'])

setup(name = 'test package',
      version = '1.0',
      description = 'Just a test package.',
      ext_modules = [module1])
</code></pre>

<p>Note: This was taken mostly from <a href="https://docs.python.org/3/extending/building.html" rel="nofollow">the python documentation</a>.</p>

<p><strong>test.cpp</strong></p>

<pre><code>#include &lt;Python.h&gt;

#include &lt;iostream&gt;
using namespace std;

int
_fib(int n)
{
    if (n &lt; 2)
        return n;
    else
        return _fib(n-1) + _fib(n-2);
}

static PyObject*
fib(PyObject* self, PyObject* args)
{
    int n;

    if (!PyArg_ParseTuple(args, "i", &amp;n))
        return NULL;

    return Py_BuildValue("i", _fib(n));
}

static PyMethodDef FibMethods[] = {
    {"fib", fib, METH_VARARGS, "Calculate the Fibonacci numbers."},
    {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initfib(void)
{
    (void) Py_InitModule("fib", FibMethods);
}
</code></pre>

<p>Note: This was taken from <a href="https://en.wikibooks.org/wiki/Python_Programming/Extending_with_C#Building_the_extension_module_with_GCC_for_Microsoft_Windows" rel="nofollow">here</a>, but I seem to get the exact same results regardless of what <code>test.cpp</code> contains, even if it's just <code>int main(){;}</code></p>