Skip to content
Latchkey

setuptools "Cython is required to compile .pyx" in CI

Your build calls cythonize on .pyx files but Cython is not present in the isolated build environment. Without Cython there is nothing to translate .pyx to C, so setuptools stops before any compiler runs.

What this error means

The build fails with a message that Cython is required to compile .pyx files, or ModuleNotFoundError: No module named 'Cython' from within setup.py.

setuptools
error: Cython is required to compile mypkg/fast.pyx to C
# or:
ModuleNotFoundError: No module named 'Cython'

Common causes

Cython missing from build-system.requires

The isolated build env only has the declared requirements. Compiling .pyx needs Cython listed there.

Shipping .pyx without pre-generated C

An sdist that contains .pyx but not the generated .c forces a Cython compile at install time, which fails if Cython is absent.

How to fix it

Add Cython to build requirements

  1. List Cython in [build-system] requires.
  2. Call cythonize in setup.py.
  3. Re-run the build.
pyproject.toml
[build-system]
requires = ["setuptools", "Cython>=3.0", "wheel"]
build-backend = "setuptools.build_meta"

Ship generated C in the sdist

Include the .c files so installers can compile without Cython.

Terminal
python -m cython mypkg/fast.pyx
python -m build --sdist

How to prevent it

  • Declare Cython in build-system.requires for any .pyx project.
  • Include generated C in sdists so end users do not need Cython.
  • Build wheels in CI to catch a missing Cython early.

Frequently asked questions

What causes ""Cython ... required ... .pyx""?
The isolated build env only has the declared requirements. Compiling .pyx needs Cython listed there.
How do I fix "Cython ... required ... .pyx"?
Add Cython to build requirements

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card