 <p>Use the option <code>-I/Users/myuser/anaconda/include/python2.7</code> in the <code>gcc</code> command. (That's assuming you are using python 2.7. Change the name to match the version of python that you are using.) You can use the command <code>python-config --cflags</code> to get the full set of recommended compilation flags:</p> <pre><code>$ python-config --cflags -I/Users/myuser/anaconda/include/python2.7 -I/Users/myuser/anaconda/include/python2.7 -fno-strict-aliasing -I/Users/myuser/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes </code></pre> <p>However, to build the extension module, I recommend using a simple setup script, such as the following <code>setup.py</code>, and let <code>distutils</code> figure out all the compiling and linking options for you.</p> <pre><code># setup.py from distutils.core import setup, Extension example_module = Extension('_example', sources=['example_wrap.c', 'example.c']) setup(name='example', ext_modules=[example_module], py_modules=["example"]) </code></pre> <p>Then you can run:</p> <pre><code>$ swig -python example.i $ python setup.py build_ext --inplace </code></pre> <p>(Take a look at the compiler commands that are echoed to the terminal when <code>setup.py</code> is run.)</p> <p><code>distutils</code> knows about SWIG, so instead of including <code>example_wrap.c</code> in the list of source files, you can include <code>example.i</code>, and <code>swig</code> will be run automatically by the setup script:</p> <pre><code># setup.py from distutils.core import setup, Extension example_module = Extension('_example', sources=['example.c', 'example.i']) setup(name='example', ext_modules=[example_module], py_modules=["example"]) </code></pre> <p>With the above version of <code>setup.py</code>, you can build the extension module with the single command</p> <pre><code>$ python setup.py build_ext --inplace </code></pre> <p>Once you've built the extension module, you should be able to use it in python:</p> <pre><code>&gt;&gt;&gt; import example &gt;&gt;&gt; example.fact(5) 120 </code></pre> <p>If you'd rather not use the script <code>setup.py</code>, here's a set of commands that worked for me:</p> <pre><code>$ swig -python example.i $ gcc -c -I/Users/myuser/anaconda/include/python2.7 example.c example_wrap.c $ gcc -bundle -undefined dynamic_lookup -L/Users/myuser/anaconda/lib example.o example_wrap.o -o _example.so </code></pre> <p>Note: I'm using Mac OS X 10.9.4:</p> <pre><code>$ gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn) Target: x86_64-apple-darwin13.3.0 Thread model: posix </code></pre>