I just resolved a problem installing a Python module pycdio on my Mac OS X 10.10.1 “Yosemite” operating system. The error message was obscure: “Error: Unable to find ‘python.swg'”, and “Error: Unable to find ‘typemaps.i'”. The solution involved something non-obvious about how Mac Ports handles swig. Here’s my notes, in hopes of helping others seeing this error.

I was trying to install pycdio, a Python language binding for libcdio, the CD Input and Control library. The “Requirements” section of the pycdio page said it required libcdio, pkg-config, and SWIG. I installed all three via MacPorts. Then I gave the command to install pycdio:

% sudo pip install pycdio
Downloading/unpacking pycdio
  Downloading pycdio-0.20.tar.gz (197kB): 197kB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/pycdio/setup.py) egg_info for package pycdio
  ...[irrelevant diagnostics omitted]...
    building '_pycdio' extension
    swigging swig/pycdio.i to swig/pycdio_wrap.c
    swig -python -outdir /private/tmp/pip_build_root/pycdio -o swig/pycdio_wrap.c swig/pycdio.i
    :3: Error: Unable to find 'python.swg'
    swig/pycdio.i:31: Error: Unable to find 'typemaps.i'
    error: command 'swig' failed with exit status 1
  ...[irrelevant diagnostics omitted]...
----------------------------------------
Cleaning up...

Now, I know SWIG is a system for wrapping interfaces to C and C++ libraries, so that they can be called from higher-level languages. It wasn’t hard to guess that SWIG was unable to wrap a necessary library _pycdio, because some files python.swg and typemaps.i were missing. I was baffled about why they would be missing. After all, I had installed SWIG.

The clue came in the macports description about port “swig”. Look at the “sub-ports” section:

% port info swig
swig @3.0.2 (devel)
Sub-ports:            swig-chicken, swig-clisp, swig-csharp, swig-d, swig-gcj,
                      swig-go, swig-guile, swig-java, swig-lua, swig-mzscheme,
                      swig-ocaml, swig-octave, swig-perl, swig-php, swig-php5,
                      swig-pike, swig-python, swig-r, swig-ruby, swig-tcl
Variants:             doc, universal

Description:          SWIG is a software development tool that connects programs
                      written in C and C++ with a variety of high-level
                      programming languages. ...[rest elided]...

There is a reference to swig-python. Sure enough, there is a separate MacPorts port “swig-python”, which contains the Python language bindings for SWIG. Installing that port fixed the problem.

% sudo port install swig-python
  ...[irrelevant diagnostics omitted]...

% sudo pip install pycdio
Downloading/unpacking pycdio
  Downloading pycdio-0.20.tar.gz (197kB): 197kB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/pycdio/setup.py) egg_info for package pycdio
  ...[irrelevant diagnostics omitted]...
    building '_pycdio' extension
    swigging swig/pycdio.i to swig/pycdio_wrap.c
    swig -python -outdir /private/tmp/pip_build_root/pycdio -o swig/pycdio_wrap.c swig/pycdio.i
    /usr/bin/clang   ...[irrelevant diagnostics omitted].../swig/pycdio_wrap.o
    ...[irrelevant diagnostics omitted]...
Successfully installed pycdio
Cleaning up...

Moral of the story: when installing SWIG with MacPorts on Mac OS X, look to see if you need to install a port specific to your target high-level language in addition to the main swig port.