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 gensimon a new Python or musl.Failed building wheel for gensimcompiling 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.
# 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 gensimCache & speed
Cache ~/.cache/pip so the gensim/NumPy/SciPy wheels are reused. Avoiding the Cython compile is the biggest speedup.
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-gensim-${{ hashFiles('requirements*.txt') }}Common errors
| Error | Cause | Fix |
|---|---|---|
| No matching distribution found for gensim | No wheel for Python/musl | Pin a supported Python; use glibc |
| Failed building wheel for gensim | Cython source build | Force --only-binary |
| command 'gcc' failed | No compiler | apt-get install build-essential |
| Build takes many minutes | Compiling Cython | Force --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.