Skip to content
Latchkey

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 directory

Common 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-dev

Prefer a wheel to skip SWIG

Terminal
pip install --only-binary :all: <package>

How to prevent it

  • Bake swig into 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →