title: SWIG: 'module' object has no attribute 'Decklist'
body: <p>I'm having one hell of a time with SWIG, due in part to the lack of good C++ examples to learn from.  I finally got my first program to compile with SWIG, but am having troubles running it.  Let me just get right to the code...</p>
  
  <p>setup.py:</p>
  
  <pre><code>#!/usr/bin/env python
  
  """
  setup.py file for SWIG example
  """
  
  from distutils.core import setup, Extension
  
  
  decklist_module = Extension('_decklist',
                             sources=['decklist_wrap.cxx', 'decklist.cpp'],
                             )
  
  setup (name = 'decklist',
         version = '0.1',
         author      = "Me",
         description = """Testing!""",
         ext_modules = [decklist_module],
         py_modules = ["decklist"],
         )
  </code></pre>
  
  <p>decklist.hpp:</p>
  
  <pre><code>#include &lt;boost/unordered_map.hpp&gt;
  
  
  
  class DeckList{
     private:
          boost::unordered_map&lt;std::string, int&gt; mainBoard;
          boost::unordered_map&lt;std::string, int&gt; sideBoard;
      public:
          void addCard(std::string name, int cardCount);
          int getCount(std::string cardName);
          DeckList();
          ~DeckList();
  
  };
  </code></pre>
  
  <p>decklist.cpp:</p>
  
  <pre><code>#ifndef DECKLIST_H
  #define DECKLIST_H
  #include "decklist.hpp"
  #include &lt;stdio.h&gt;
  
  DeckList::DeckList(){
  
  }
  
  void DeckList::addCard(std::string cardName, int cardCount){
      mainBoard[cardName] = cardCount;
  }
  
  int DeckList::getCount(std::string cardName){
      return mainBoard[cardName];
  }
  
  #endif    
  </code></pre>
  
  <p>decklist.i:</p>
  
  <pre><code>//decklist.i
  %module decklist
  %{
      #include "decklist.hpp"
  %}
  #include "decklist.hpp"
  </code></pre>
  
  <p>Now on the terminal (I am on Ubuntu Natty Narwhal), I run the following two commands:</p>
  
  <pre><code>swig -python -c++ decklist.i
  python setup.py build_ext --inplace
  </code></pre>
  
  <p>The second gives me the following response:</p>
  
  <pre><code>running build_ext
  building '_decklist' extension
  gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c decklist_wrap.cxx -o build/temp.linux-x86_64-2.7/decklist_wrap.o
  cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
  gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c decklist.cpp -o build/temp.linux-x86_64-2.7/decklist.o
  cc1plus: warning: command line option "-Wstrict-prototypes" is valid for Ada/C/ObjC but not for C++
  g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/decklist_wrap.o build/temp.linux-x86_64-2.7/decklist.o -o /home/aespiel1/deck/_decklist.so
  </code></pre>
  
  <p>But I wind up with:</p>
  
  <pre>
  decklist.cpp
  decklist.hpp
  decklist.i
  decklist.py
  decklist.pyc
  _decklist.so
  decklist_wrap.cxx
  setup.py
  </pre>
  
  <p>and a build folder with <code>.o</code> files for both the <code>decklist_wrap</code> and <code>decklist</code> files.</p>
  
  <p>If I run python in idle and switch into this directory and:</p>
  
  <pre><code>import decklist
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#2&gt;", line 1, in &lt;module&gt;
        import decklist
  ImportError: No module named decklist
  </code></pre>
  
  <p>Strangely, if I run it from the terminal, I can <code>import decklist</code>.  But then a command like:</p>
  
  <pre><code>dl = decklist.DeckList()  
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'module' object has no attribute 'DeckList'
  </code></pre>
  
  <p>What am I doing wrong?  I am so frustrated.</p>