title: .so module doesnt import in python: dynamic module does not define init function
body: <p>I am trying to write a python wrapper for a C function. After writing all the code, and getting it to compile, Python can't import the module. I am following the example given <a href="http://csl.sublevel3.org/C-functions-from-Python/" rel="nofollow">here</a>. I reproduce it here, after fixing some typos. There is a file myModule.c:</p>
  
  <pre><code>#include &lt;Python.h&gt;
  
  /*
   * Function to be called from Python
   */
  static PyObject* py_myFunction(PyObject* self, PyObject* args)
  {
      char *s = "Hello from C!";
      return Py_BuildValue("s", s);
  }
  /*
   * Bind Python function names to our C functions
   */
  static PyMethodDef myModule_methods[] = {
      {"myFunction", py_myFunction, METH_VARARGS},
      {NULL, NULL}
  };
  
  /*
   * Python calls this to let us initialize our module
   */
  void initmyModule()
  {
      (void) Py_InitModule("myModule", myModule_methods);
  }
  </code></pre>
  
  <p>Since I am on a Mac with Macports python, I compile it as</p>
  
  <pre><code>$ g++ -dynamiclib -I/opt/local/Library/Frameworks/Python.framework/Headers -lpython2.6 -o myModule.dylib myModule.c
  $ mv myModule.dylib myModule.so
  </code></pre>
  
  <p>However, I get an error when I try to import it.</p>
  
  <pre><code>$ ipython
  In[1]: import myModule
  ---------------------------------------------------------------------------
  ImportError                               Traceback (most recent call last)
  
  /Users/.../blahblah/.../&lt;ipython console&gt; in &lt;module&gt;()
  
  ImportError: dynamic module does not define init function (initmyModule)
  </code></pre>
  
  <p>Why can't I import it?</p>