Skip to content
Latchkey

How to Install gensim in CI Without Slow Source Builds

gensim has fast wheels, but a too-new Python or an Alpine image drops you into a slow Cython compile against NumPy and SciPy.

gensim depends on NumPy and SciPy and ships manylinux wheels with its Cython extensions prebuilt, so installs are normally quick. CI breaks when no wheel matches the interpreter and pip compiles the Cython code, needing a C compiler plus a working NumPy/SciPy.

Why it fails in CI

With no matching wheel, pip builds gensim from source, compiling Cython extensions against NumPy headers. Slim and Alpine images lack the compiler, and the build is slow enough to dominate the pipeline. The usual trigger is a brand-new Python with no wheel yet.

  • No matching distribution found for gensim on a new Python or musl.
  • Failed building wheel for gensim compiling Cython from sdist.
  • error: command 'gcc' failed - no compiler on the image.

Install it reliably

Keep the wheel with a glibc base image and a Python gensim ships wheels for, and force-binary so a missing wheel fails fast. Install a compiler only as a last resort.

Terminal
# Force the prebuilt wheel (no Cython compile)
pip install --only-binary=:all: gensim

# Source build fallback (Debian/Ubuntu)
apt-get update && apt-get install -y build-essential python3-dev
pip install gensim

Cache & speed

Cache ~/.cache/pip so the gensim/NumPy/SciPy wheels are reused. Avoiding the Cython compile is the biggest speedup.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.cache/pip
    key: pip-gensim-${{ hashFiles('requirements*.txt') }}

Common errors

ErrorCauseFix
No matching distribution found for gensimNo wheel for Python/muslPin a supported Python; use glibc
Failed building wheel for gensimCython source buildForce --only-binary
command 'gcc' failedNo compilerapt-get install build-essential
Build takes many minutesCompiling CythonForce --only-binary

Key takeaways

  • gensim has wheels - force --only-binary to skip the Cython compile.
  • Glibc base + a supported Python keeps you off the source build.
  • Cache ~/.cache/pip; gensim follows NumPy/SciPy wheel availability.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →