title: Unknown type name 'PyModuleDef'
body: <p>I'm working with Python and C++ integration, and I'm on MacOS.</p>
  <p>When I use all of the <code>PyObject</code> methods they all seem to work but none of the <code>PyModule</code> methods seem to be working.</p>
  <p>This is my code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;vector&gt;
  
  #if PY_MAJOR_VERSION &gt;= 3
  #define PY3K
  #endif
  
  #ifdef __APPLE__
  #include &lt;Python/Python.h&gt;
  #else
  #include &lt;Python.h&gt;
  #endif
  
  #define space &quot; &quot;
  #define epoch int(1000)
  
  using namespace std;
  
  double hypothesis(const std::vector&lt;double&gt;&amp; b_val, double x){
      return b_val[0] + b_val[1] * x;
  }
  
  std::vector&lt;double&gt; regression(const std::vector&lt;double&gt;&amp; x, const std::vector&lt;double&gt;&amp; y,
                                 int epochs, double learning_rate){
      if(!epochs) epochs = epoch;
      double _m = 0;
      double _b = 0;
      std::vector&lt;double&gt; _values(2);
      int N = x.size();
  
      for(int i = 0; i &lt; epochs; i++){
          _values[0] = _b, _values[1] = _m;
          double dm = 0;
          double db = 0;
          double cost = 0;
  
          for(int j = 0; j &lt; N; j++){
              double p = hypothesis(_values, x[j]);
              cost += pow(y[j] - p, 2);
              dm += (-2.0 / N) * (x[j] * (y[j] - p));
              db += (-2.0 / N) * (y[j] - p);
          }
  
          cost /= N;
          _m = _m - (learning_rate * dm);
          _b = _b - (learning_rate * db);
  
          if ((i + 1) % 100 == 0)
              std::cout &lt;&lt; &quot;Epoch: &quot; &lt;&lt; (i + 1) &lt;&lt; &quot; Cost: &quot; &lt;&lt; cost &lt;&lt; std::endl;
      }
      std::vector&lt;double&gt; result(2);
      result[0] = _m, result[1] = _b;
      return result;
  }
  
  static PyObject * fit(PyObject * self, PyObject * args){
      PyObject *x;
      PyObject *y;
      double learning_rate;
      int epochs;
      int N;
  
      if(!PyArg_ParseTuple(args, &quot;00di0i&quot;, &amp;x, &amp;y, &amp;epochs, &amp;learning_rate, &amp;N)){
          return nullptr;
      }
  
      std::vector&lt;double&gt; _x(N), _y(N);
      for(int i = 0; i &lt; N; i++){
          _x[i] = PyFloat_AsDouble(PyList_GetItem(x, (Py_ssize_t)i));
          _y[i] = PyFloat_AsDouble(PyList_GetItem(y, (Py_ssize_t)i));
      }
  
      std::vector&lt;double&gt; _result = regression(_x, _y, epochs, learning_rate);
      PyObject *result = PyTuple_New(2);
      for(int i = 0; i &lt; 2; i++){
          PyTuple_SetItem(result, i, PyFloat_FromDouble(_result[i]));
      }
  
      return Py_BuildValue(&quot;s&quot;, result);
  }
  
  static PyMethodDef linreg_methods[] = {
          {&quot;fit&quot;, (PyCFunction)fit, METH_VARARGS, &quot;Linear Regression&quot;},
          {nullptr}
  };
  
  static PyModuleDef linear_regression = {
          PyModuleDef_HEAD_INIT,
          &quot;linear_regression&quot;
          &quot;Linear Regression&quot;,
          -1,
          linreg_methods
  };
  
  PyMODINIT_FUNC PyInit_linear_regression(void){
      return PyModule_Create(&amp;linear_regression);
  }
  </code></pre>
  <p>The output I get is <code>error: unknown type name 'PyModuleDef'</code>.</p>
  <p>I can't seem to understand what the problem is.</p>