Python "error: command 'swig' failed" Building a Package in CI
A package generates C/C++ bindings with SWIG during its build, but the swig executable is not installed on the runner. The build aborts before the compiler even runs.
What this error means
A source build fails with error: command 'swig' failed: No such file or directory. Packages like auto-sklearn, m2crypto, or pocketsphinx need SWIG to generate wrappers, which a slim image lacks.
Build output
building 'M2Crypto._m2crypto' extension
swigging SWIG/_m2crypto.i to SWIG/_m2crypto_wrap.c
error: command 'swig' failed: No such file or directoryCommon causes
SWIG not installed on the runner
The package’s build step calls swig to generate wrapper sources. Without the swig package present, the build cannot proceed.
No prebuilt wheel for this platform
With no compatible wheel, pip falls back to the source build that needs SWIG. A wheel would skip the SWIG step entirely.
How to fix it
Install SWIG (and the toolchain)
Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y swig build-essential python3-devPrefer a wheel to skip SWIG
Terminal
pip install --only-binary :all: <package>How to prevent it
- Bake
swiginto images that build SWIG-based bindings. - Prefer wheels in CI so the SWIG step is skipped.
- Pin a Python version with wheel coverage for such packages.
Related guides
Python.h Not Found Despite python3-dev Installed in CIFix "fatal error: Python.h: No such file or directory" in CI when python3-dev is installed but for the wrong…
Python "gcc: error: unrecognized command line option" in CIFix "gcc: error: unrecognized command line option" building a Python extension in CI - a compiler flag baked…
Python "ld: cannot find -lz" Linking a C Extension in CIFix "/usr/bin/ld: cannot find -lz" (or -lssl, -ljpeg) building a Python extension in CI - the linker cannot f…